• Post Reply Bookmark Topic Watch Topic
  • New Topic

NoClassDefFoundError from class in jar  RSS feed

 
Jack Bercy
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Here's my setup:

I have a bunch of libraries that are jarred in different jars in directory X.

I have a program that I have put in a different jar, P.jar, in directory Y.

I move to directory Y.

I launch my program with this command :

java -cp ./P.jar:absolute_path_to_directory_X/*:./ package.for.my.class.containing.main.Program

The program starts fine.

At one point, I instantiate class A, which sits in A.jar in directory X, and class A uses class B, which also sits in the same X directory.

When A initializes, it crashes with a NoClassDefFoundError for class B in the clinit of class A.

I have verified that all classes are in their respective directories.

It's as if classes in jar files in X directory don't use the same classpath that I've specified on the command line ?

Why would that be, or is my problem something else altogether ?
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
*Classes* do not use classpath at all. The JVM uses the classpath. It does not use a different classpath for different jars.

This is almost certainly something that is wrong that you do not see because you are convinced it is already ok. Try making a simple little program that uses 6 or 8 classes; jar them in the same configuration you have your big program, and be sure to have package names of a similar complexity. If THAT doesn't work, you can post it. But I'd give even money that, once you do that, that it will work, and it may well lead you find the spelling error or the jar file that was zipped to hold absolute paths or whatever that is preventing this from happening.

Half of debugging is being convinced at the outset that the error IS THERE and that it is almost certain to be something YOU DID.

rc
 
Paul Clapham
Sheriff
Posts: 22823
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You didn't say what operating system you were using. Yes, it does make a difference. In Unix-like systems the colon is used to separate classpath entries, whereas in Windows the semicolon is used.

So ir you're using Windows, you're using the wrong separator.
 
Jack Bercy
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:You didn't say what operating system you were using. Yes, it does make a difference. In Unix-like systems the colon is used to separate classpath entries, whereas in Windows the semicolon is used.

So ir you're using Windows, you're using the wrong separator.


It is indeed Linux.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!