This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing classes in other jars from my jar

 
Sri Nivas
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
also,
tell me how u r running ur application from command line?
and the CLASSPATH setting u've..
regards
maulin
 
Sri Nivas
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic