views:

379

answers:

2

Hi, 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.

Thank you Ido

+1  A: 

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

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.

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:

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:

Export-Package: name.seller.rich,
 name.seller.rich.junit,
 name.seller.rich.foo,
 ...
Rich Seller
it's 200 mb of jar files... i wanted to add it as variables
Ido
For it to be used by Eclipse a jar either needs to be nested in a plugin, or be a plugin. The only alternative would be for you to create a custom classloader to reference the jar, but then you'd still have to define a way to deliver the jar and ensure its in the right place. Much simpler to add it to a plugin and export all the packages.
Rich Seller
This jar might be updated, and every user of my plug-in will have it on his computer. I do not want to supply it with my plug-in.
Ido
I've had a look around, I don't think you have much choice: http://wiki.eclipse.org/FAQ_How_can_I_share_a_JAR_among_various_plug-ins%3F
Rich Seller
I have seen an interesting book about bundling by reference:http://book.javanb.com/eclipse-rich-client-platform-designing-coding-and-packaging-java-applications-oct-2005/ch20lev1sec4.htmlI still couldn't got it to work though...
Ido
+1  A: 

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

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

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...

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.

Andreas_D
Each client of my plugin have this jar on his computer, and i do not want him to have another copy, because the jar might update by the 3rd party.
Ido