引用非插件项目到eclipse插件项目

时间:2022-12-07 17:59:17

Can I add a reference from an eclipse plugin project to a non plugin jar? This is a jar that I can not change, so i have to use it as is.

我可以将eclipse插件项目中的引用添加到非插件jar吗?这是一个我无法改变的罐子,所以我必须按原样使用它。

Thank you Ido

谢谢Ido

2 个解决方案

#1


The safest approach would be to create a new plugin from your existing jar file:

最安全的方法是从现有的jar文件创建一个新的插件:

Select New project -> Plug-In Development -> Plug-in from existing JAR Archives

从现有JAR Archives中选择New project - > Plug-In Development - > Plug-in

Then choose the jar file(s) ('Add Externals' on Galileo), name the project and fill in some plug-in properties (optional) and choose whether you want to unzip the jar or keep it as it is. I keep the checkbox checked...

然后选择jar文件(在Galileo上添加'外部'),命名项目并填写一些插件属性(可选),并选择是要解压缩jar还是保持原样。我保持选中复选框...

And that's it. Eclipse will autogenerate a plugin project that exports all packages so that it can be used in your plug-in or rcp project.

就是这样。 Eclipse将自动生成一个导出所有包的插件项目,以便可以在插件或rcp项目中使用它。

#2


The simplest way to do this is to add the jar to your plugin and modify the classpath.

最简单的方法是将jar添加到插件中并修改类路径。

Copy the jar into a sub-directory of the plugin (e.g. lib), then modify the plugin's classpath (in the manifest editor) to include the plugin root and lib/foo.jar.

将jar复制到插件的子目录(例如lib)中,然后修改插件的类路径(在清单编辑器中)以包含插件根和lib / foo.jar。

In the Manifest Editor, select the Runtime tab and select the Add button on the Classpath pane. Add the jar, e.g. "lib/foo.jar" and select OK, if you look at the manifest source you should see a line like:

在Manifest Editor中,选择Runtime选项卡,然后选择Classpath窗格中的Add按钮。添加罐子,例如“lib / foo.jar”并选择确定,如果查看清单源,您应该看到如下行:

Bundle-ClassPath: lib/foo.jar,
 .

If the jar is to be used by other plugins, you can configure the manifest to export the packages in the nested jar, then other plugins can add a dependency to the containing plugin and use it as normal. To do so go to the Runtime tab of the Manifest editor, select Add.. on the Exported Packages section, then select all the packages to be exported. If you look at the manifest you should see all the packages listed like this:

如果jar将由其他插件使用,则可以配置清单以在嵌套jar中导出包,然后其他插件可以向包含插件添加依赖项并正常使用它。为此,请转到Manifest编辑器的Runtime选项卡,在Exported Packages部分选择Add ..,然后选择要导出的所有包。如果您查看清单,您应该看到所有列出的包如下所示:

Export-Package: name.seller.rich,
 name.seller.rich.junit,
 name.seller.rich.foo,
 ...

#1


The safest approach would be to create a new plugin from your existing jar file:

最安全的方法是从现有的jar文件创建一个新的插件:

Select New project -> Plug-In Development -> Plug-in from existing JAR Archives

从现有JAR Archives中选择New project - > Plug-In Development - > Plug-in

Then choose the jar file(s) ('Add Externals' on Galileo), name the project and fill in some plug-in properties (optional) and choose whether you want to unzip the jar or keep it as it is. I keep the checkbox checked...

然后选择jar文件(在Galileo上添加'外部'),命名项目并填写一些插件属性(可选),并选择是要解压缩jar还是保持原样。我保持选中复选框...

And that's it. Eclipse will autogenerate a plugin project that exports all packages so that it can be used in your plug-in or rcp project.

就是这样。 Eclipse将自动生成一个导出所有包的插件项目,以便可以在插件或rcp项目中使用它。

#2


The simplest way to do this is to add the jar to your plugin and modify the classpath.

最简单的方法是将jar添加到插件中并修改类路径。

Copy the jar into a sub-directory of the plugin (e.g. lib), then modify the plugin's classpath (in the manifest editor) to include the plugin root and lib/foo.jar.

将jar复制到插件的子目录(例如lib)中,然后修改插件的类路径(在清单编辑器中)以包含插件根和lib / foo.jar。

In the Manifest Editor, select the Runtime tab and select the Add button on the Classpath pane. Add the jar, e.g. "lib/foo.jar" and select OK, if you look at the manifest source you should see a line like:

在Manifest Editor中,选择Runtime选项卡,然后选择Classpath窗格中的Add按钮。添加罐子,例如“lib / foo.jar”并选择确定,如果查看清单源,您应该看到如下行:

Bundle-ClassPath: lib/foo.jar,
 .

If the jar is to be used by other plugins, you can configure the manifest to export the packages in the nested jar, then other plugins can add a dependency to the containing plugin and use it as normal. To do so go to the Runtime tab of the Manifest editor, select Add.. on the Exported Packages section, then select all the packages to be exported. If you look at the manifest you should see all the packages listed like this:

如果jar将由其他插件使用,则可以配置清单以在嵌套jar中导出包,然后其他插件可以向包含插件添加依赖项并正常使用它。为此,请转到Manifest编辑器的Runtime选项卡,在Exported Packages部分选择Add ..,然后选择要导出的所有包。如果您查看清单,您应该看到所有列出的包如下所示:

Export-Package: name.seller.rich,
 name.seller.rich.junit,
 name.seller.rich.foo,
 ...