开发者

Compiling and executing a java program with a jar library package

I am trying to compile and execute a java program which uses JTidy. I've managed to compile the program using the following command:

javac -classpath jtidy-r938.jar @sourcefile

This seems to work just fine. However, when 开发者_Go百科I try to run the program with the following command (Top is the name of the class containing the main portion of the program):

java -classpath jtidy-r938.jar Top

I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: Top
Caused by: java.lang.ClassNotFoundException: Top
...
Could not find the main class: Top. Program will exit.

This is mostly likely a very dumb question with a simple solution, but it is driving me insane. Please help!!


Are you using the fully qualified name of the class Top here i.e. is your class Top packageless? If not, you need to provide the fully qualified class name for the above command to work. Make sure you also put in other JAR dependencies in the classpath by separating them with ; or : depending on your target platform.

EDIT: Also, as mentioned below, make sure you also include . (or the appropriate location) in your classpath if your class dependencies are not just in the JAR but also .class files on your file system.


You are removing the path "." (current directory) from the classpath when you set it.

Try java -classpath .;jtidy-r938.jar Top.

That way it should be able to find your class.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜