开发者

Java command-line problems with .jar libraries

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 c开发者_如何转开发ompiles 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!


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜