aspose file tools*
The moose likes Java in General and the fly likes Accessing classes in other jars from my jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Accessing classes in other jars from my jar" Watch "Accessing classes in other jars from my jar" New topic
Author

Accessing classes in other jars from my jar

Sri Nivas
Ranch Hand

Joined: Apr 18, 2001
Posts: 58
I have an small application which has several classes. I have created a jar by combining all this classes and in the manifest file, made one of my classes as the main class.
All of my classes in my jar file, use some classes from an external jar log4j.jar.
I am not able to access the classes in the log4j.jar file. I get a NoClassDefFound error.
Is there any way I can solve this problem without writing my own class loader?
Do I need to change my manifest.mf?
Sri.
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
hi,
as long as u've log4j.jar in ur CLASSPATH it should work...
how u r trying to use those classes? and what error you are getting??
regards
maulin
Sri Nivas
Ranch Hand

Joined: Apr 18, 2001
Posts: 58
Even if I keep log4j.jar in my classpath, I am getting this error.
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
If I write all my application in a single java file, then it is working. But the moment I use a jar file, I get the above error.
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
hi sri,
well u can try one thing,
in the CLASSPATH...
if u've sequence,
yourJAR;log4j.jar then change it to be,
log4j.jar;yourJAR...
sequence does matter i guess..
regards
maulin
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
also,
tell me how u r running ur application from command line?
and the CLASSPATH setting u've..
regards
maulin
Sri Nivas
Ranch Hand

Joined: Apr 18, 2001
Posts: 58
Hello Maulin,
Let me first thank you for the help and your time.
I am executing my jar like this
java -jar MyJar.jar
My manifest.mf looks like this.
Manifest-Version: 1.0
Main-Class: MyMain
Classpath: lib/log4j-1.2.8.jar
My classpath setting is like this:
CLASSPATH=c:\jakarta-log4j-1.2.8\dist\lib\log4j-1.2.8.jar
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1824

Originally posted by Sri Nivas:
My manifest.mf looks like this.
Manifest-Version: 1.0
Main-Class: MyMain
Classpath: lib/log4j-1.2.8.jar

Classpath is the incorrect key. It should read:
Class-Path: lib/log4j-1.2.8.jar
And I believe that this setting overrides the system CLASSPATH, so it does not matter what that environment setting is.
Hope that this helps.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Accessing classes in other jars from my jar