将 jars 添加到 Eclipse 插件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5744520/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 20:08:42  来源:igfitidea点击:

Adding jars to a Eclipse PlugIn

eclipsepluginsimportjar

提问by ethnix

I try to build a Eclipse plugin that has to use a self written jar which is dependent on other jars, but I don't get the point where to start with handling jars as seperate PlugIns. Anywhere I have to use just the .jar files or am I wrong?

我尝试构建一个 Eclipse 插件,该插件必须使用依赖于其他 jar 的自写 jar,但我不知道从哪里开始将 jar 作为单独的插件处理。我必须在任何地方使用 .jar 文件还是我错了?

回答by ethnix

I think I found a proper solution; the trick is that you have to implement all the files via Eclipse. I just copy here the solution which was posted to news.eclipse.platform:

我想我找到了一个合适的解决方案;诀窍是您必须通过 Eclipse 实现所有文件。我只是将发布到 news.eclipse.platform 的解决方案复制到这里:



Include the jars in a plugin:

将 jars 包含在插件中:



  1. Use Import> File Systemto import the jar files into your plugin project, say in the <project>/libdirectory.
  2. Use Add...button to add the jars to the classpath section of the plugin.xml> Runtimetab.
  3. Use New...button to add "." library back (with no quotes, of course).
  4. Make sure your binary build exports the new jar files on the plugin.xml> Buildtab.
  5. Save
  6. On the project, use context menu> PDE Tools> Update Classpathto correctly add the jars to the eclipse project classpath.
  1. 使用Import>File System将 jar 文件导入您的插件项目,例如在<project>/lib目录中。
  2. 使用Add...按钮将 jar 添加到plugin.xml>Runtime选项卡的类路径部分。
  3. 使用New...按钮添加“.” 图书馆回来(当然没有引号)。
  4. 确保您的二进制构建在plugin.xml>Build选项卡上导出新的 jar 文件。
  5. 节省
  6. 在项目中,使用context menu> PDE Tools>Update Classpath在罐子正确添加到Eclipse项目的classpath。

回答by Paul Webster

What is a self-written jar?

什么是自写jar?

Normally you turn 3rd party jars into bundles using an OSGi MANIFEST.MF (See New>Plug-in Development>Plug-in from Existing JAR archive) or you include them in your plugin.jar and add extra Bundle-ClassPath entries as mentioned by TomaC.

通常,您使用 OSGi MANIFEST.MF(请参阅新建>插件开发>现有 JAR 存档中的插件)将第 3 方 jar 转换为包,或者将它们包含在 plugin.jar 中并添加额外的 Bundle-ClassPath 条目,如上述提到的托马 C.

If you mean at runtime your plugin will create a new jar and needs to load it, that's different, though.

如果您的意思是在运行时您的插件将创建一个新的 jar 并需要加载它,那是不同的。

回答by TomaC

Project Properties -> Java Build Path -> Add External jars. Is this what you are looking for?

项目属性 -> Java 构建路径 -> 添加外部 jar。这是你想要的?