简体   繁体   English

操纵Eclipse插件的java类路径?

[英]Manipulate the java class path of an Eclipse plugin?

I am working on a plugin that consist of a homemade view to Eclipse. 我正在开发一个包含自制Eclipse视图的插件。 When I run the plugin and display the classpath using System.getProperty("java.class.path") I get this as output : D:\\Programs\\eclipse\\plugins\\org.eclipse.equinox.launcher_1.3.100.v20150511-1540.jar 当我运行插件并使用System.getProperty("java.class.path")显示类路径时,我将其作为输出: D:\\Programs\\eclipse\\plugins\\org.eclipse.equinox.launcher_1.3.100.v20150511-1540.jar

I would like to add some .jar files for the proper functioning of my view, but I can't figure out how... I guess you can do it by adding some specifications to the MANIFEST.MF of the plugin but I don't know how to do it propely. 我想添加一些.jar文件以便我的视图正常运行,但我无法弄清楚...我想你可以通过在插件的MANIFEST.MF中添加一些规范来实现它但我不知道我知道如何正确地做到这一点。 any ideas ? 有任何想法吗 ?

Each Eclipse plugin has its own classpath. 每个Eclipse插件都有自己的类路径。 To use additional jars in the plugin you need to include them in the plugin. 要在插件中使用其他jar,您需要将它们包含在插件中。

Add your jars to the plugin directory. 将您的jar添加到插件目录。 Usually they are put in a 'lib' directory. 通常它们放在'lib'目录中。

Open the plugin MANIFEST.MF editor and on the 'Runtime' tab in the 'Classpath' section click the 'Add...' button and add your jars to the class path. 打开插件MANIFEST.MF编辑器,在“Classpath”部分的“Runtime”选项卡上单击“Add ...”按钮,然后将jar添加到类路径中。

On the 'Build' tab of the editor make sure the 'lib' folder is include in the Binary Build section. 在编辑器的“构建”选项卡上,确保“二进制构建”部分中包含“lib”文件夹。

Your MANIFEST.MF should end up with a `Bundle-Classpath' entry that looks something like: 您的MANIFEST.MF应该以“Bundle-Classpath”条目结束,类似于:

Bundle-ClassPath: .,
 lib/jogg-0.0.7.jar,
 lib/jorbis-0.0.15.jar,
 lib/vorbisspi1.0.2.jar

(here I have 3 jars in a lib folder). (这里我在lib文件夹中有3个罐子)。

The build.properties file should be something like: build.properties文件应该类似于:

bin.includes = META-INF/,\
               .,\
               plugin.xml,\
               lib/,\
               lib/jogg-0.0.7.jar,\
               lib/jorbis-0.0.15.jar,\
               lib/vorbisspi1.0.2.jar

The best approach I've found is to create a lib directory in your Eclipse project (where your view is contained). 我发现最好的方法是在Eclipse项目中创建一个lib目录(包含你的视图)。 Place your .jar files in said lib directory. 将.jar文件放在所说的lib目录中。

Then using the editor on the MANIFEST.MF, you add the .jar files to the classpath. 然后使用MANIFEST.MF上的编辑器,将.jar文件添加到类路径中。 If you wish to export the packages, you then add to the Exported Packages as well. 如果要导出包,则还要添加到“导出的包”。 MANFIEST.MF

Depending upon what you are doing, you may wish/need to also update the Build Configuration. 根据您的操作,您可能希望/还需要更新构建配置。 构建配置

If you examine the MANIFEST.MF file itself, you will then see an entry for Bundle-ClassPath . 如果检查MANIFEST.MF文件本身,您将看到Bundle-ClassPath的条目。 It will list your entries. 它会列出您的参赛作品。 Here it has the standard "." 这里有标准的“。” for the project, a resources/ directory that we export, and a couple of .jar files. 对于项目,我们导出的resources/目录,以及几个.jar文件。

Bundle-ClassPath: .,
resources/,
lib/aopalliance-1.0.jar,
lib/apccore-client-2.11.8.jar,
lib/cglib-nodep-2.2.2.jar,
lib/ehcache-2.10.3.jar,
...

Note that in our experience, it is also necessary to adjust the Java Build Path from the Properties of the project itself. 请注意,根据我们的经验,还需要从项目本身的属性中调整Java构建路径。 A user commented that this step may not be necessary. 用户评论说可能没有必要执行此步骤。 We are on an older version of Eclipse due to our product, so YMMV, If needed (usually compile failures are the indicator), you then need to add, via the properties context menu on the project, the .jar files to the "Java Build Path" (you can do the same with a resources directory). 由于我们的产品,我们使用的是Eclipse的旧版本,因此YMMV,如果需要(通常编译失败是指标),则需要通过项目的属性上下文菜单将.jar文件添加到“Java”构建路径“(您可以对资源目录执行相同操作)。

Java构建路径

This will allow you to properly build using the .jar files. 这将允许您使用.jar文件正确构建。

For Compile time we need to add it to the Project runtime library. 对于编译时,我们需要将其添加到Project运行时库中。

For the run time you have to package the jar either in your EAR/WAR file or Load it to the Application server as a App server libraries. 对于运行时,您必须将jar打包在EAR / WAR文件中,或者将其作为App服务器库加载到应用程序服务器。

Please let me know if you need further assistance on this. 如果您需要进一步的帮助,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM