Execute a Java .jar file *which depends on other .jar files*?

Superwormy

Golden Member
Feb 7, 2001
1,637
0
0
I tried java -classpath "./smack.jar" -jar MyJarFile.jar and it doesn't work...

I get this error:

# > java -classpath "/path/to/smack.jar" -jar "Jabber Client.jar"
Exception in thread "main" java.lang.NoClassDefFoundError: org/jivesoftware/smack/filter/PacketFilter
at ConnectionFactory.create(ConnectionFactory.java:61)
at Client.<init>(Client.java:233)
at Client.main(Client.java:43)


What am I doing wrong? If I choose Project -> Run As Java Application in Eclipse it works fine... so I build the .jar file, and now I want to run it outside of Eclipse.
 

mundane

Diamond Member
Jun 7, 2002
5,603
8
81
I ran into a similar problem. You need to specify the other .jars inside of your manifest file.
Reference: http://java.sun.com/docs/books/tutorial/deployment/jar/downman.html

To do so in Eclipse, export to jar but save the manifest file (so you can reuse it). Edit the classpath entry inside of the manifest to include the required .jar files, and for each subsequent export re-use that manifest file instead of having Eclipse generate a new one.

When running .jar files, Java ignores both the CLASSPATH environment variable and the command line argument.