I have common code between a Java application and an RCP application. So I have created an OSGI bundle which contains:
I built all with Tycho Manifest-first and it worked fine until I needed to use an external jar in my common code.
I need to use jsch so I have add jsch in my MANIFEST.MF :
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Main-Class: mygroupid.Main
Bundle-Name: Common tools
Bundle-SymbolicName: common-tools
Bundle-Version: 1.0.1.qualifier
Export-Package: mygroupid,
mygroupid.tools
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: org.osgi.framework;version="1.3.0"
Require-Bundle: com.jcraft.jsch;bundle-version="0.1.46"
I build my RCP application with Tycho and it works. But when I run the bundle as pure JAR with java -jar myjar.jar
, I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/jcraft/jsch/JSchException
If I export my bundle with Eclipse, it works. So I have an error in my tycho configuration...
How to solve this problem ? Is there a jar-with-dependencies for Tycho ? It seems not to be the case What I have missed ?
(My configuration: Eclipse Juno with m2e, Tycho 0.16.0, p2: Juno, Tycho: packaging>eclipse-plugin, target-platform-configuration : resolver=p2 and pomDependencies=consider.)
Just add the maven-assembly-plugin to your build, and let it build a jar with all dependencies:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
Alternatively, you can also create an assembly where the jars are packed individually. You'll need to write your own assembly descriptor for this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With