Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NoClassDefFoundError when using jar

 
Bruce McGuire
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.

I have an application that I am running, which uses a class contained in a jar file that is on the classpath.

For some reason, it is not being found.

Do the files in the jar need to be listed in the jar's manifest file? If so, is there an easy way to have Ant create the manifest file when creating the jar?

Thanks,

Bruce.
 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, the classes don't need to be listed in the manifest for a jar to be picked up on the classpath.

Please post more details, including your classpath, what java version, the command you are using to run and what kind of application it is.

You probably already checked your classpath really carefully for missing ; or : and verified you're including the jar name in the classpath (c:\somedir\somejar.jar or /somedir/somejar.jar)
 
peer
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello.

I have the same problem. I'm really confused about this Class-Path entry as I have tryied numerous times to use it, but with no measurable result. Anhow: here is a description of what I am doing:

Manifest.MF looks like this:

Manifest-Version: 1.0
Created-By: 1.5.0_01 (Sun Microsystems Inc.)
Main-Class: my.example.MyClass
Class-Path: servlet.jar

the directory content where the jar this manifest file comes from looks like this:

21.04.2005 09:01 607.245 myjar.jar
03.10.2004 11:17 76.880 servlet.jar

when I try calling it with java -jar it results in

C:\somewhere>java -jar myjar.jar
Exception in thread "main" java.lang.NoClassDefFoundError: Ljavax/servlet/ServletRequest;
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Unknown Source)
at java.lang.Class.getDeclaredField(Unknown Source)
...

whereas this version :

C:\somewhere>java -classpath servlet.jar;myjar.jar my.example.MyClass

works perfectly fine.

additional information:

C:\somewhere>java -version
java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode)

Anybody got an Idea what I am missing here???

Thanks in advance,
Greetz
Y
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"ypsilon",

We're pleased to have you here with us on the Ranch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender
 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"ypsilon",

I followed instructions like these in the past to get it to work:Jar file Tutorial - manifest file - classpath

Note that the white space is critical.

Warning: The text file must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.


Did you post the manifest file that you pulled back out of the jar? If not, take a look at it. Sometimes it loses the last line or doesn't really use your manifest file at all.
[ April 21, 2005: Message edited by: Carol Enderlin ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic