简体   繁体   中英

Exporting jar libraries in an Eclipse plugin

I am working on an Eclipse plugin that has several components. Previously this was a single plugin and everything worked great. However, I recently broke this into multiple plugins that are part of a single feature.

The structure is there are a whole bunch of plugins in the feature. There is one "core" plugin that contains common code and libraries. Every other plugin relies on the core plugin.

The problem is while the plugins compile fine and there are no warnings regarding the plugin.xml, manifest, etc., the plugins do not work at runtime due to missing classes. Specifically, I have Google Guava in the core plugin and the classes in the Guava jar cannot be found at runtime. There are other jars but this is the first one to blow up.

I have tried several ways to resolve this:

  • Exporting packages contained in the Guava jar in the core project has the same results: does not work.
  • Putting the Guava jar in each plugin does work, but is undesirable due to the extra size.
  • According to my searches, I can add a <runtime> tag to my plugin.xml, which Eclipse promptly ignores because I have a manifest. I have not found a way to add an equivalent setting to the manifest.

The only way that actually works is to create a library plugin which essentially unpacks and merges all of the jar files. The problem here is I then have a mishmash of random files. If I want to upgrade a jar file, it is tedious to regenerate the project and I suspect would be clear as mud when searching through SVN history for the project.

Is there another way to accomplish this that makes it easy to drop in updated jar files and have it work with minimal changes?

Exporting packages contained in the Guava jar in the core project has the same results: does not work.

Have your wondered on this?

As far as I am aware, In Eclipse Equinox is OSGi container and in OSGi we have the facility of using other bundles resources.

So, here make sure that you are exporting the right things from the right place.

Probably, the other bundles are not able to recognize the classes exported from core bundle (check import-package here in all your child bundles) OR something miss-happenings in classloaders.

Try using "Eclipse-Buddy policy" attribute in manifest. It may work :-)

Something that I do and work is:

  1. Create a Maven project and put all your dependencies there
  2. Write your code including algorithms, and all the logic of your plugin/app
  3. Build the project. You will have one big jar file. Something like "myproject-with-dependencies.jar"
  4. In Eclipse:
    1. Right click -> Plug-in from Existing JAR Archives. 在此处输入图片说明
    2. Select your jar file from step 3.
    3. Check your plugin.xml and export only the desired packages( in order to avoid ClassCastExpeption in Osgi)
  5. Finally add a dependency to this plug-in from the other plug-ins you have

Notes:

  • This is what I use in order to avoid p2 sites and also jars to bundles(specially because I use Tycho to build my Eclipse plug-ins).
  • This is not the best solution but will save you lot of time. Trust me!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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