我目前正在尝试使用 Slick 和 Maven 构建一个简单的 java 游戏。
我的设置确实可以正常工作。但是,当我将主类扩展为 Slick“BasicGame”时,我无法再执行 jar,提示此错误消息:
D:\workspace\GameTest\target>java -jar GameTest-1.0-SNAPSHOT.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/newdawn/slick/BasicGame
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
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$000(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)
Caused by: java.lang.ClassNotFoundException: org.newdawn.slick.BasicGame
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)
... 12 more
Could not find the main class: gameTest.MyGame. Program will exit.
在我这样做之前,一切都执行得很好。Pom.xml 是从这里复制的。
MyGame 类如下所示: ... 导入 ...
public class MyGame extends BasicGame {
...
empty implementations of BasicGame Methods
...
public static void main(String[] args){
System.out.println("Hello World");
}
}
有谁知道为什么会发生这个错误?