LWJGL NoClassDefFoundError [英] LWJGL NoClassDefFoundError
问题描述
我目前正在运行带有Java 7 update 21的Linux Mint 14 Nadia 64位,并且正在使用LWGL 2.9.我还使用了一个makefile来编译和运行所有内容.
I am currently running Linux Mint 14 Nadia 64bit with Java 7 update 21, and I'm using LWGL 2.9. I am also using a makefile to compile and run everything.
我遇到的问题是,当我尝试运行从命令行编译的JAR( make run
)时(请参见下面的源代码),我收到此错误消息:
My problem I have is when I try to run my JAR (make run
) that I compiled from command line (see source below), I get this error message:
Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/LWJGLException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2451)
at java.lang.Class.getMethod0(Class.java:2694)
at java.lang.Class.getMethod(Class.java:1622)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: org.lwjgl.LWJGLException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 6 more
make: *** [run] Error 1
之前,我在通过 javac
(通过 make
)进行编译时遇到了同样的问题,但是我通过添加 -cp $(LIB_FILES)来解决了该问题.
标志添加到 javac
命令.因此,我尝试将其添加到 java
命令中(通过 make run
),但这并不能解决我的问题.
Before, I had the same problem with compiling via javac
(via make
), but I fixed it by just adding the -cp $(LIB_FILES)
flag to the javac
command. So, I tried adding that to the java
command (via make run
), but it didn't fix my problem.
我的下一个猜测是,我需要将 Djava.library.path
设置为本地文件夹,该文件夹也不起作用.我已经提供了我认为需要的所有信息,但是如果您需要更多信息,请问.
My next guess was that I needed to set Djava.library.path
to the native folder, which also did not work. I have supplied all the information I think is needed, but if you need more, just ask.
目录布局:
Platform-Jumper
+ class
+ net/netne/platinumcoding/platformer (shortened to save space)
- Main.class
+ dist
- Executable.jar
+ lib
+ native
+ (freeusb/linux/macosx/solaris/windows)
- jinput.jar
- lwjgl.jar
- lwjgl_util.jar
- Makefile
- MANIFEST.MF
- README.md
+ res
(Image files)
+ src
+ net/netne/platinumcoding/platformer (shortened to save space)
- Main.java
(为原始Makefile分配给Manzill0) Makefile
:
(Credit to Manzill0 for the original Makefile)
Makefile
:
JC := javac
JAR := jar
MODULES := net/netne/platinumcoding/platformer
SRC_DIR := $(addprefix src/,$(MODULES))
CLASS_DIR := $(addprefix class/,$(MODULES))
SO_DIR := "lib/native/linux"
LIB_FILES := lib/lwjgl.jar:lib/lwjgl_util.jar:lib/jinput.jar
SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.java))
OBJ := $(patsubst src/%.java,class/%.class,$(SRC))
vpath %.java $(SRC_DIR)
.PHONY: all checkdirs clean
all: checkdirs dist/Executable.jar
dist/Executable.jar: $(OBJ)
$(JAR) cvfm $@ MANIFEST.MF -C $(CLASS_DIR)/ .
$(OBJ): $(SRC)
$(JC) -cp $(LIB_FILES) -d $(CLASS_DIR) $<
checkdirs: $(SRC_DIR) $(CLASS_DIR) $(LIB_DIR)
$(CLASS_DIR):
@mkdir -p $@
clean:
@rm -rf $(BUILD_DIR)
@rm -f dist/Executable.jar
run:
java -cp $(LIB_FILES) -Djava.library.path=$(SO_DIR) -jar dist/Executable.jar
Main.java
:
package net.netne.platinumcoding.platformer;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
public class Main {
public static void main(String[] args) {
new Main().start();
}
public void start() {
try {
Display.setDisplayMode(new DisplayMode(800, 600));
} catch (LWJGLException e) {
e.printStackTrace();
}
while (!Display.isCloseRequested()) {
Display.update();
Display.sync(60);
}
Display.destroy();
}
}
注意:如果您需要文件的内容,我已将其上传到 GitHub @ https://github.com/DealerNextDoor/Platform-Jumper
Note: If you need the content of files, I have this uploaded to GitHub @ https://github.com/DealerNextDoor/Platform-Jumper
推荐答案
我发现了我的问题所在.我将 -jar
标志与 -cp
标志混合在一起.为了解决这个问题,我所要做的就是将 JAR 文件添加到我的类路径中,然后运行我的主类.
I found out what my problem was. I was mixing the -jar
flag with the -cp
flag. To fix this problem, all I had to do was add the JAR file to my classpath, and then run my main class.
所以没有:
-cp lib/lwjgl.jar:lib/lwjgl_util.jar:lib/jinput.jar
我会用
-cp lib/lwjgl.jar:lib/lwjgl_util.jar:lib/jinput.jar:dist/Executable.jar
这可以解决问题.
这篇关于LWJGL NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!