File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Ant, Maven and Other Build Tools and the fly likes NoClassDefFoundError when using jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "NoClassDefFoundError when using jar" Watch "NoClassDefFoundError when using jar" New topic

NoClassDefFoundError when using jar

Bruce McGuire

Joined: Apr 04, 2005
Posts: 1

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?


Carol Enderlin
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
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)

Joined: Apr 21, 2005
Posts: 1

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,
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63852


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.

Forum Bartender

[Asking smart questions] [About Bear] [Books by Bear]
Carol Enderlin
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364

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 ]
I agree. Here's the link:
subject: NoClassDefFoundError when using jar
It's not a secret anymore!