Reputation: 51
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.)
Upvotes: 5
Views: 747
Reputation: 11723
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.
Upvotes: 1
Reputation: 1042
if you are working on Linux/Unix platform, you can try java -classpath :myjar.jar com.yourpackage.mainclass
if you are workin on windows platform, you can try java -classpath ;myjar.jar com.yourpackage.mainclass
Upvotes: 0