嘿那里。
我正在用 vim 用 lwjgl 编写游戏,我正在尝试用 jdb 进行调试,但我遇到了一些问题。
首先,我向您展示我的项目树。(主类是Engine.java)。
.
├── build
│ ├── classes
│ │ └── com
│ │ └── ionsoft
│ │ ├── engine
│ │ │ ├── Draw.class
│ │ │ ├── Engine.class
│ │ │ └── Timer.class
│ │ └── game
│ │ └── Game.class
│ └── jar
│ └── Jump2Box.jar
├── build.properties
├── build.xml
├── lib
│ ├── jars
│ │ ├── lwjgl.jar
│ │ ├── lwjgl_util.jar
│ │ └── slick-util.jar
│ └── natives-linux
│ ├── libjinput-linux64.so
│ ├── libjinput-linux.so
│ ├── liblwjgl64.so
│ ├── liblwjgl.so
│ ├── libopenal64.so
│ └── libopenal.so
├── LICENCE
├── README
├── src
│ └── com
│ └── ionsoft
│ ├── engine
│ │ ├── Draw.java
│ │ ├── Engine.java
│ │ └── Timer.java
│ └── game
│ └── Game.java
└── tags
我正在使用 javac 调试选项用 ant 编译我的项目。这里有 build.xml 文件中的编译部分:
<!-- Compile -->
<target name="compile">
<mkdir dir="${classes.dir}" />
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath" debug="true" includeantruntime="false" />
</target>
当我尝试调试应用程序时,问题就出现了。我阅读了手册页,发现有一个类路径选项。由于我使用的是 lwjgl,我想我需要包含 .class 文件的路径。
我正在从项目的根目录执行此代码。
ruby@Cedrus ~/development/java/projects/Jump2Box $ jdb -classpath build/classes com.ionsoft.engine.Engine
Initializing jdb ...
> run
run com.ionsoft.engine.Engine
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
>
VM Started:
Exception occurred: java.lang.ClassNotFoundException (uncaught)"thread=main", java.lang.ClassLoader.loadClass(), line=436 bci=121
main[1] cont
Exception in thread "main" > java.lang.NoClassDefFoundError: org/lwjgl/LWJGLException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2521)
at java.lang.Class.getMethod0(Class.java:2764)
at java.lang.Class.getMethod(Class.java:1653)
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:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 6 more
The application exited
我也注意到了这个奇怪的例外。
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
我在这里找到了这篇解释解决方案的帖子。
ignore uncaught java.lang.Throwable
我不确定我需要把这行代码放在哪里才能解决这个问题。我还需要包含 lwjgl 的 .class 吗?我不知道我做错了什么。
更新:
我将 lwjgl 包含在我的类路径中,它现在仍然运行良好。我还包括了我的源文件的路径。
ruby@Cedrus ~/development/java/projects/Jump2Box $ jdb -launch -classpath build/classes/com/ionsoft/engine/:build/classes/com/ionsoft/game/:lib/jars/ -sourcepath src/com/ionsoft/engine/:src/com/ionsoft/game/ Engine
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
Initializing jdb ...
>
VM Started: No frames on the current call stack
main[1] stop in Engine.main
Deferring breakpoint Engine.main.
It will be set after the class is loaded.
main[1] cont
>
Exception occurred: java.lang.NoClassDefFoundError (uncaught)"thread=main",java.lang.ClassLoader.loadClass(), line=436 bci=121
main[1] next
Excep> tion in thread "main" java.lang.NoClassDefFoundError: Engine (wrong name: com/ionsoft/engine/Engine)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
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:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
The application exited
如果我尝试将 JVM 作为 jdb 的服务器运行,则会出现相同的错误。
设置 JVM 服务器
ruby@Cedrus ~/development/java/projects/Jump2Box $ java -classpath build/classes/com/ionsoft/engine/:build/classes/com/ionsoft/game/:lib/jars/ -agentlib:jdwp=transport=dt_socket,address=localhost:8888,server=y,suspend=y Engine
Listening for transport dt_socket at address: 8888
连接jdb
ruby@Cedrus ~/development/java/projects/Jump2Box $ jdb -sourcepath src/com/ionsoft/engine/:src/com/ionsoft/game/ -connect com.sun.jdi.SocketAttach:hostname=localhost,port=8888
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
Initializing jdb ...
>
VM Started: No frames on the current call stack
main[1] stop in Engine.main
Deferring breakpoint Engine.main.
It will be set after the class is loaded.
main[1] cont
>
Exception occurred: java.lang.NoClassDefFoundError (uncaught)"thread=main",java.lang.ClassLoader.loadClass(), line=436 bci=121
main[1] list
Source file not found: ClassLoader.java
main[1] next
>
The application exited
在“发生异常”时,JVM 显示相同的错误。
Exception in thread "main" java.lang.NoClassDefFoundError: Engine (wrong name: com/ionsoft/engine/Engine)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
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:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
我看到名称有问题,但我不知道如何解决。
当我使用 lwjgl 运行我的 jar 文件时,我需要将本机文件附加到 jar 中。我用蚂蚁做这个操作。这是我执行此操作的目标。
<!-- Run generated jar -->
<target name="run" depends="jar">
<java fork="true" classname="${main-class}">
<classpath>
<path refid="classpath" />
<path location="${jar.dir}/${ant.project.name}.jar" />
</classpath>
<sysproperty key="java.library.path" value="${lwjgl_natives.dir}" /> </java>
</target>
感谢您的时间。