File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Java JARs With Dependancies On Other JARs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java JARs With Dependancies On Other JARs" Watch "Java JARs With Dependancies On Other JARs" New topic
Author

Java JARs With Dependancies On Other JARs

Jason Mowat
Ranch Hand

Joined: Aug 17, 2003
Posts: 79
Greetings,

I have a JAR file that contains some generic base classes and interfaces.

I have a second JAR file that contains concrete implementations of the classes and interfaces from the first JAR. The second JAR also has a main class specified in the manifest of the second JAR.

Both JAR1 and JAR2 are in the same directory.

I am having classpath problems when I try to run the second jar. I have tried the following:

java -jar jar2.jar -classpath c:\path_to_dir\jar1.jar
java -jar jar2.jar -classpath .;c:\path_to_dir\jar1.jar
java -jar jar2.jar -classpath "c:\path_to_dir\jar1.jar"
java -classpath c:\path_to_dir\jar1.jar -jar jar2.jar
java -cp c:\path_to_dir\jar1.jar -jar jar2.jar
etc...

I get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError:jar1_package/Jar1Class

Any suggestions on what I could be doing wrong?

Thanks,
Jason
Scott Dunbar
Ranch Hand

Joined: Sep 23, 2004
Posts: 245
I'm really not a big fan of the -jar option as I think it is a little bit confusing. Try:

java -cp jar1.jar:jar2.jar the.class.name.that.has.your.main

Replace the : with a ; if you are on windows.
[ December 08, 2004: Message edited by: Scott Dunbar ]

<a href="http://forums.hotjoe.com/forums/list.page" target="_blank" rel="nofollow">Java forums using Java software</a> - Come and help get them started.
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

In order to use the -jar option, you need to specify various settings in the jar's manifest file. See this thread for more information on executable jars.

Oh, the -jar option means that the JVM will ignore the system CLASSPATH and any classpath entered with the -cp option. Only the Class-Path specified in the manifest file (and the boot classes...) will be used.
[ December 08, 2004: Message edited by: Joel McNary ]

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
If the above suggestions still don't help, a little more information will probably be helpful for us to point you in the right direction. At the least, it would be nice to see the contents of your manifest file (if you provide one) and the contents of the two jar files. You can get the jar file contents by running the following command:


Keep Coding!

Layne


Java API Documentation
The Java Tutorial
Pradeep Kadambar
Ranch Hand

Joined: Oct 18, 2004
Posts: 148
One solution is to set the classpath in the manifest.MF file of the jar

Manifest-Version: 1.0
Main-Class: MainApp
Class-Path: 1.jar 2.jar 3.jar 4.jar
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java JARs With Dependancies On Other JARs
 
Similar Threads
Access class files between two jar files
Archive problem.
Access class files between two jar files
jar versioning
ClassNotFoundException