我有一個java文件,它使用jfreechart庫,使用本地驅動器中的文本文件並顯示圖形。日食運行良好。但是,我想從cmd提示符下運行此命令,其他簡單的Java文件能夠通過cmd prmnt成功運行,但無法運行此文件。 PS:MyTool.java能夠無誤地編譯並創建類文件,但無法運行。能夠編譯但無法從cmd運行Java與jar文件
1) This is how I am compiling it in cmd prompt: (gives 0 errors)
C:\Documents and Settings\hello.maga\workspace\MyTool\lib>javac -cp "gnujaxp.
jar;iText-2.1.5.jar;jcommon-1.0.16.jar;jfreechart-1.0.13.jar;jfreechart-1.0.13-e
xperimental.jar;jfreechart-1.0.13.jar;junit.jar;servlet.jar;swtgraphics2d.jar" MyTool.java
2) This is how I am running it:
C:\Documents and Settings\hello.maga\workspace\MyTool\lib>java -cp "gnujaxp.j
ar;iText-2.1.5.jar;jcommon-1.0.16.jar;jfreechart-1.0.13.jar;jfreechart-1.0.13-ex
perimental.jar;jfreechart-1.0.13.jar;junit.jar;servlet.jar;swtgraphics2d.jar" MyTool
Error for second command:
Exception in thread "main" java.lang.NoClassDefFoundError: MyTool
Caused by: java.lang.ClassNotFoundException: MyTool
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: MyTool. Program will exit.
我不明白的是,如果有任何錯誤,那麼它不應該排在首位編譯,可以有人教我。非常感謝你。