我试图将我的检查程序从Eclipse导出到可运行的jar文件中。我收到了一个jar文件,但它没有运行...它给了我关于未找到的类的神秘错误消息。它不是包含所有需要的类的jar文件的重点吗?我不知道现在该做什么。
这是我运行jar时得到的结果:
D:\Dokumente\workspace>java -jar Dame.jar
Exception in thread "main" java.lang.NoClassDefFoundError: [[Lcheckers/Board$EmptySquare;
at checkers.Board.<init>(Board.java:63)
at checkers.Board.<init>(Board.java:49)
at checkers.GameUI.main(GameUI.java:105)
Caused by: java.lang.ClassNotFoundException: checkers.Board$EmptySquare
at java.net.URLClassLoader$1.run(Unknown Source)
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)
... 3 more
也许知道EmptySquare
是Board
的内部类有帮助吗?
可能是什么问题呢?我试过两个&#34;提取所需的库&#34;和#34;打包所需的库&#34;在导出向导中。
我也尝试过使用命令行中的jar
,但它也不起作用。这就是我的所作所为:
D:\Dokumente\workspace\Dame\bin\checkers>jar cvfe Dame.jar checkers.GameUI *.class
D:\Dokumente\workspace\Dame\bin\checkers>java -jar Dame.jar
Fehler: Hauptklasse checkers.GameUI.class konnte nicht gefunden oder geladen werden
(error: main class checkers.GameUI.class could not be found or loaded)
如果我遗漏主要类的包名(GameUI
),它也不起作用:
D:\Dokumente\workspace\Dame\bin\checkers>jar cvfe Dame.jar GameUI *.class
D:\Dokumente\workspace\Dame\bin\checkers>java -jar Dame.jar
Exception in thread "main" java.lang.NoClassDefFoundError: GameUI (wrong name: checkers/GameUI)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
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)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
毫无头绪。
jar文件内容为:
D:\Dokumente\workspace\Dame\bin\checkers>jar tvf Dame.jar
0 Thu Jan 09 01:05:26 CET 2014 META-INF/
88 Thu Jan 09 01:05:26 CET 2014 META-INF/MANIFEST.MF
994 Thu Jan 09 00:14:30 CET 2014 Board$1.class
1840 Thu Jan 09 00:14:30 CET 2014 Board$EmptySquare.class
447 Thu Jan 09 00:14:30 CET 2014 Board$GamePiece.class
4051 Thu Jan 09 00:14:30 CET 2014 Board$Piece.class
4399 Thu Jan 09 00:14:30 CET 2014 Board$Queen.class
8381 Thu Jan 09 00:14:30 CET 2014 Board.class
2946 Thu Jan 09 00:14:30 CET 2014 Checkers.class
2708 Thu Jan 09 00:14:30 CET 2014 CheckersAB.class
4202 Thu Jan 09 00:14:30 CET 2014 CheckersABT.class
2464 Thu Jan 09 00:14:30 CET 2014 CheckersMinMax.class
1324 Thu Jan 09 00:14:30 CET 2014 CheckersPieces.class
951 Thu Jan 09 00:14:30 CET 2014 GameState.class
804 Thu Jan 09 00:14:30 CET 2014 GameUI$1.class
663 Thu Jan 09 00:14:30 CET 2014 GameUI$2.class
2535 Thu Jan 09 00:14:30 CET 2014 GameUI.class
739 Thu Jan 09 00:14:30 CET 2014 GUIBoard$1.class
6069 Thu Jan 09 00:14:30 CET 2014 GUIBoard.class
3776 Thu Jan 09 00:14:30 CET 2014 Move.class
607 Thu Jan 09 00:14:30 CET 2014 MoveComparator.class
610 Thu Jan 09 00:14:30 CET 2014 NodeVal.class
1078 Thu Jan 09 00:14:30 CET 2014 PlayCheckersAB.class
356 Thu Jan 09 00:14:30 CET 2014 PlayCheckersABT.class
357 Thu Jan 09 00:14:30 CET 2014 PlayCheckersMM.class
2466 Thu Jan 09 00:14:30 CET 2014 PlayTournament.class
1183 Thu Jan 09 00:14:30 CET 2014 Square.class
241 Thu Jan 09 00:14:30 CET 2014 ZeroSumGame.class
答案 0 :(得分:0)
好的,我找到了答案。在帖子eclipse doesn't compile the project中 有人建议切换到新工作区。我这样做是因为除了神秘的非工作jar文件之外,Eclipse也不再构建我的java文件了。我切换到一个新工作区,重新导入项目,瞧,导出的jar文件是可以运行的!
感谢您的努力,特别是对于divanov!