aspose file tools*
The moose likes Beginning Java and the fly likes referencing jars from a jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "referencing jars from a jar" Watch "referencing jars from a jar" New topic
Author

referencing jars from a jar

Thomas Rochon
Ranch Hand

Joined: Jul 11, 2002
Posts: 72
Hi folks !
There's my stupid question:
I've got an application (just one class file) which
I put into a jar archive. It's done by eclipse, using
the export to jar function. So the manifest is also created
by eclipse.
My application is using some classes from another jar which I
import into my application. But that's the problem. Even if
I put my own jar file into the same folder where the other jars
(the one I imported into my application) are, the JVM cant find them.
After starting my application by double clicking my jar file,
the JVM is telling me, "no class def found" (regarding the
classes I imported to my app).
So - What's wrong? Do I have to add a statement into
the manifest?
I would be very happy to hear from you.
Thanx ! - Thomas -
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Hi Thomas -
Not a stupid question at all.
Treat the name of any JAR file as a directory itself in a classpath environment. To put something called jehosophat.jar into the classpath, for example, this won't work:

This will:


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Thomas Rochon
Ranch Hand

Joined: Jul 11, 2002
Posts: 72
Hi Michael !
Thank you very much for your reply!
I created a batch file in which I call my app
java -jar myApp.jar
Befor that I set the classpath (absolute) with:
set CLASSPATH=D:/path/to/libs/ALib.jar
That's the lib from which I import the needed classes
into my app.
But when starting the batch the JVM tells me:
Exception in thread "main" java.lang.NoClassDefFoundError: iaik/pkcs/pkcs11/Module
Or do I have to set the classpath into the manifest file ?
Thanx! - Thomas -
[ December 16, 2003: Message edited by: Thomas Rochon ]
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Hi Thomas - Assuming all the needed classes are in ALib.jar and myApp.jar, and you've correctly imported everything, that should work. One way to verify this is to examine the contents of the library jar to ensure the directory structure is as you expect.
All your manifest file should have to do at this point is specify the Main-Class in the myApp.jar.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Thomas, where is the iaik.pkcs.pkcs11.Module class? If it's in a JAR file in your CLASSPATH, did you check it to make sure it really is?
Also, you might like to know that it's perfectly possible to put a JAR inside of another JAR when packaging applications. Take a look at the Creating an Executable JAR File thread for a simple example.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Thomas Rochon
Ranch Hand

Joined: Jul 11, 2002
Posts: 72
I thank all of you for your replies !
Maybe I'm a bit stupid, but after all I get the same
error message as before. I set the classpath for the
according jar file. I checked it with "set CLASSPATH"
and my jar is shown.
I also imported this jar correctly into my application,
because this one is running fine inside my eclipse ide.
I even packed the needed jar archive into my own jar file.
But the result is always the same: "Exception in thread "main" java.lang.NoClassDefFoundError: iaik/pkcs/pkcs11/Module".
*sniff*
Thomas Rochon
Ranch Hand

Joined: Jul 11, 2002
Posts: 72
I got it ...
java -cp "C:\lib\iaikPkcs11Wrapper-1.2.11.jar";"C:\lib\InitToken.jar" com.whatever.pkcs11.tools.InitToken
That's how I start my application, now. And it works fine.
Thanks to all of you!
- Thomas -
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: referencing jars from a jar