• Post Reply Bookmark Topic Watch Topic
  • New Topic

Questions about classpath and jar  RSS feed

 
Donald Fung
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I had wrote an executable jar that send mail by using the org.apache.commons.mail package (many other programs useing it). And I'd compiled it and tested it before jar. That's fine.

After I jar it and execute it. It displayed the following error: Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/mail/EmailException"

According to the sun document, it seems that I need to put the jar file of the mail package in relative path in the executable jar, rewrite the manifest.MF and jar all the file together.


As the package need to be shared by many programs, it's better for load the package in a common location. How can the jar to get the packge in environment CLASSPATH?
[ July 28, 2006: Message edited by: Donald Fung ]
 
Dana Bothner-By
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How many is "many" programs? Unless space is *tight*, it makes more sense for each program to have its own copy of this library jar. (For example, over time, different programs may require different versions of this jar file.) Avoid messing with the CLASSPATH environment variable -- you're not really saving yourself any work.
 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could set the CLASSPATH as an environment variable in your OS. That would make it available for other Java applications.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chengwei Lee:
You could set the CLASSPATH as an environment variable in your OS. That would make it available for other Java applications.

No, when you run an executable JAR file by double clicking it or by running it from the command line using the "-jar" switch (java -jar myprogram.jar), the CLASSPATH environment variable (and also the "-cp" and "-classpath" switches on the command line) are ignored.

So setting the CLASSPATH environment variable will not work in this case.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!