简体   繁体   中英

Include 3rd party jars in bundle

I'm trying to include 3rd party jar in my bundle. I'm following this tutorial http://www.aqute.biz/Blog/2007-02-19 , but in my Activator i get ClasNotFoundException while trying to refer to a class from that external jar.

My bundle jar directory structure:

-\MyBundle
  -\plugin.xml
  -\META-INF
    -\MANIFEST.MF
  -\org
    -\mybundle
      -\Activator.class
  -\3rdParty.jar

MANIFEST.MF looks like this:

...
Bundle-ClassPath: .,
 3rdParty.jar
...

It's a part of Eclipse 3.5.1 RCP application.

Error message:

java.lang.ClassNotFoundException: 3rd.party.proxy.ConfiguratorProxy
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:494)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:398)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:105)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at my.program.eclipse.core.ProcessEditorUploaderActivator.start(ProcessEditorUploaderActivator.java:111)

But when I'm invoking this.getClass().getResource("/3rdParty.jar") it works.

Edit: problem solved . I had to remove org.eclipse.core.runtime, org.eclipse.equinox.app and org.eclipse.osgi directories from my RCP app. Information about bundles classpath was cached.

Are you running it from Eclipse? If so, your thirdparty bundle should also be listed in your .classpath file. You should have a line like:

<classpathentry exported="true" kind="lib" path="lib/thirdparty.jar"/>

(This should happen automatically when using the MANIFEST editor)

If you are exporting the plugin and running it some other way, you'll need a build.properties file, that should look something like:

source.. = src/ 
output.. = classes/ 
bin.includes = META-INF/,\
           .,\
           lib/thirdparty.jar

Some things to check:

  • Is your 3rdParty.jar really inside the bundle jar? Open with Winzip and check.

  • Is your Manifest.MF correct? Try putting all entries of the Bundle-ClassPath: on one line, no new lines: Bundle-ClassPath: .,3rdParty.jar

  • Where are you trying to access the classes from? The classes of the internal jar will be visible from the classes of MyBundle.jar, but they won't be visible from other bundles in the framework, unless you export the packages in the manifest!

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