GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Can't get a jar to run with dependencies Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Can Watch "Can New topic
Author

Can't get a jar to run with dependencies

M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 388
I have a jar file that has two dependent jar files. The files are included in the main jar. When I try to run it, I get "java.lang.NoClassDefFoundError: EZTaxJavaJNI/EZTaxJNI" which is a class inside one of the dependent jar files.

I am running this in the same dir as the jar file.
Here is my command line:
java -classpath ".;" -jar eztaxTcp.jar 1001 "C:\TWSales Tax 342\EZTaxJavaCpp.dll" "C:\TWSales Tax 342"

Any ideas?
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
I think that when you use the -jar option it ignores the -classpath option as well as the system CLASSPATH variable. In this case, you need to add a Class-Path property to your manifest file to help Java locate the correct classes.

HTH

Layne


Java API Documentation
The Java Tutorial
Chris Johnston
Ranch Hand

Joined: Dec 13, 2004
Posts: 85
Would placing the dependencies in the /lib directory and including that directoy in the jar file not solve this problem?

This would make the tree structure of the jar file look something like this:

/ (root)
|-- src
| |-- (java files)
|-- lib
| |-- (dependencies)
`-- Manifest


www.fuzzylizard.com
M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 388
Well, what I ended up doing was packaging the .class files rather than the .jar file. Its working now. Thanks
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18874
    
  40

Originally posted by M Burke:
Well, what I ended up doing was packaging the .class files rather than the .jar file. Its working now. Thanks


I'm not sure if I read your original question correctly. Did you say that you put the dependent jar files inside your main jar file?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 388
Yes, I put the dependent jars inside the main jar file. But the JRE could not find it.
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

As far as I know, The JRE cannot find jars inside of jars. What you have to do is a Layne said: include a Class-Path attribute in your manifest file.


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
Originally posted by Joel McNary:
As far as I know, The JRE cannot find jars inside of jars. What you have to do is a Layne said: include a Class-Path attribute in your manifest file.

And distribute the JARs separately. I just ran into this problem in a recent project. We decided to package all the dependent jars into a zip file and the user would then have to unzip it and put all the jar files into the same folder. Our own JAR had the Class-Path attribute set to find the dependencies if this procedure was followed correctly.

Layne
 
Don't get me started about those stupid light bulbs.
 
subject: Can't get a jar to run with dependencies