Home » Eclipse Projects » Equinox » How to use external jar?
How to use external jar? [message #1005358] |
Fri, 25 January 2013 04:55 |
kilosi mesdor Messages: 6 Registered: January 2013 |
Junior Member |
|
|
Hello,
I have a bunch of external jars(around 10) that I use for one of my bundles. For example, I use the commons-lang3-3.1.jar for various things. When I run my OSGi framework in Eclipse - it all works great. I just need to make sure I add them to my bundle's class path.
However, when I execute it outside of Eclipse, it throws java.lang.NoClassDefFoundError: errors. I'm not sure why this is happening.
I've done a bit of research and it seems that I have really two options:
1. Place the jar file in the root directory of my bundle (in this case, the bundle's jar file), and then make sure that the manifest file has a proper Export-Package on it.
I have tried this - and it still cannot find the jar.
2. Make a bundle of the jar file, and install that, ensuring all dependencies are resolved. THIS does NOT work for jar files. However, if I copy the actual source and use that instead of a jar file within the bundle, then it works. But I won't be able to do this for all of my jars since the source isn't present and I don't want to have to build every single external jar I use...
I'm pretty new to OSGi, and any help would be useful.
The below is from option 1:
Stacktrace:
java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
at ats.server.ATSActivator.start(ATSActivator.java:58)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:783)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:774)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:755)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:370)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:284)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:276)
at org.eclipse.osgi.framework.internal.core.FrameworkCommandProvider._start(FrameworkCommandProvider.java:252)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.osgi.framework.internal.core.FrameworkCommandInterpreter.execute(FrameworkCommandInterpreter.java:155)
at org.eclipse.osgi.framework.internal.core.FrameworkConsole.docommand(FrameworkConsole.java:156)
at org.eclipse.osgi.framework.internal.core.FrameworkConsole.runConsole(FrameworkConsole.java:141)
at org.eclipse.osgi.framework.internal.core.FrameworkConsole.run(FrameworkConsole.java:105)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtils
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:506)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 18 more
Here is the manifest file:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: ATS
Bundle-SymbolicName: ATS
Bundle-Version: 1.0.0.1
Bundle-Activator: ats.server.ATSActivator
Private-Package: org.apache.commons.lang3,
org.apache.commons.lang3.builder,
org.apache.commons.lang3.concurrent,
org.apache.commons.lang3.event,
org.apache.commons.lang3.exception,
org.apache.commons.lang3.math,
org.apache.commons.lang3.mutable,
org.apache.commons.lang3.reflect,
org.apache.commons.lang3.text,
org.apache.commons.lang3.text.translate,
org.apache.commons.lang3.time,
org.apache.commons.lang3.tuple
Import-Package: ats_socketer,
org.apache.commons.lang3,
org.apache.commons.lang3.builder,
org.apache.commons.lang3.concurrent,
org.apache.commons.lang3.event,
org.apache.commons.lang3.exception,
org.apache.commons.lang3.math,
org.apache.commons.lang3.mutable,
org.apache.commons.lang3.reflect,
org.apache.commons.lang3.text,
org.apache.commons.lang3.text.translate,
org.apache.commons.lang3.time,
org.apache.commons.lang3.tuple,
org.osgi.framework;version="1.3.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ClassPath: .,
../.,
akuma-1.8.jar,
ATSMailer.jar,
commons-lang3-3.1.jar,
junit-4.3.1.jar,
mail.jar,
pewParser.jar,
platform-3.4.0.jar
Require-Bundle: ATS_Socketer;bundle-version="1.0.0"
Export-Package: org.apache.commons.lang3,
org.apache.commons.lang3.builder,
org.apache.commons.lang3.concurrent,
org.apache.commons.lang3.event,
org.apache.commons.lang3.exception,
org.apache.commons.lang3.math,
org.apache.commons.lang3.mutable,
org.apache.commons.lang3.reflect,
org.apache.commons.lang3.text,
org.apache.commons.lang3.text.translate,
org.apache.commons.lang3.time,
org.apache.commons.lang3.tuple
The .jar file is in the root directory of this bundle. It is in included in the class path and the export...I also see it in the packages command:
org.apache.commons.lang3; version="0.0.0"<ATS_1.0.0.1 [14]>
org.apache.commons.lang3.builder; version="0.0.0"<ATS_1.0.0.1 [14]>
org.apache.commons.lang3.concurrent; version="0.0.0"<ATS_1.0.0.1 [14]>
org.apache.commons.lang3.event; version="0.0.0"<ATS_1.0.0.1 [14]>
org.apache.commons.lang3.exception; version="0.0.0"<ATS_1.0.0.1 [14]>
org.apache.commons.lang3.math; version="0.0.0"<ATS_1.0.0.1 [14]>
org.apache.commons.lang3.mutable; version="0.0.0"<ATS_1.0.0.1 [14]>
org.apache.commons.lang3.reflect; version="0.0.0"<ATS_1.0.0.1 [14]>
org.apache.commons.lang3.text; version="0.0.0"<ATS_1.0.0.1 [14]>
org.apache.commons.lang3.text.translate; version="0.0.0"<ATS_1.0.0.1 [14]>
org.apache.commons.lang3.time; version="0.0.0"<ATS_1.0.0.1 [14]>
org.apache.commons.lang3.tuple; version="0.0.0"<ATS_1.0.0.1 [14]>
I am confused as to why this doesn't work - it can be seen by the framework - my bundle just can't load it!!
Thanks.
[Updated on: Fri, 25 January 2013 05:19] Report message to a moderator
|
|
| | | |
Re: How to use external jar? [message #1005467 is a reply to message #1005419] |
Fri, 25 January 2013 14:54 |
kilosi mesdor Messages: 6 Registered: January 2013 |
Junior Member |
|
|
Well, you guys were very helpful - it turns out I wasn't actually putting the jars in my main jar file. DOH! I was also able to clean up the manifest file to be better.
At least it was an easy fix
I have ran into another issue, that I do not understand and would like to fix.
During Eclipse, it seems to find everything from the SDK just fine, for example, various classes from org.xml.sax. However, when I run the bundle outside of Eclipse, I run into issues where the bundle can't find it suddenly! Like this:
Exception in thread "Thread-11" java.lang.NoClassDefFoundError: org/xml/sax/helpers/DefaultHandler
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.defineClass(DefaultClassLoader.java:188)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClass(ClasspathManager.java:580)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findClassImpl(ClasspathManager.java:550)
So I have to import all of these specific packages on the manifest editor and then do a rebuild. But it seems like bnd could solve this issue for me, after looking at the top link. I'll check it out!
Thanks!
[Updated on: Fri, 25 January 2013 15:03] Report message to a moderator
|
|
| | | |
Goto Forum:
Current Time: Fri Sep 20 09:11:38 GMT 2024
Powered by FUDForum. Page generated in 0.06971 seconds
|