views:

46

answers:

1

Hi -- I have a single .java (driver.java) file I'm trying to compile and run from the command-line. It uses the external library called EXT.jar, whose structure is just a folder called EXT with a few dozen classes within it.

So I run:

javac -cp EXT.jar driver.java

This compiles the class just fine.

then when I run:

java -cp EXT.jar driver

I get a java.lang.NoClassDefFoundError.

Oddly enough, if I unpack the JAR (so now I have a folder in the root directory called EXT), the last command works just fine!! Driver will execute!

Is there any way I can make the driver.class look for the need class files from EXT.jar/EXT/*class instead of an actual EXT folder?

Thanks!

+4  A: 

You're compiling the class to the local directory. So when you run it, you need to include the current directory in your classpath. E.g.:

java -cp .;EXT.jar driver

Or in linux:

java -cp .:EXT.jar driver

With the way you have it now, you're saying your classpath is only EXT.jar (along with whatever is in the CLASSPATH environment variable) and nothing else (which is why the current directory, where driver.class is located, is excluded)

Matt
Perfect! Thanks!
Monster
@Monster - No problem. Please don't forget to accept answers to your questions (I see your accept rate is 54%)
Matt
Will do. I apparently need to wait 15 minutes to accept an answer :)
Monster