File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't get a jar to run with dependencies

 
M Burke
Ranch Hand
Posts: 399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3061
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Chris Johnston
Ranch Hand
Posts: 85
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
M Burke
Ranch Hand
Posts: 399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, what I ended up doing was packaging the .class files rather than the .jar file. Its working now. Thanks
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
M Burke
Ranch Hand
Posts: 399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I put the dependent jars inside the main jar file. But the JRE could not find it.
 
Joel McNary
Bartender
Posts: 1824
Eclipse IDE Java Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Layne Lund
Ranch Hand
Posts: 3061
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic