Domanda

Hei there.

I'm programming a game with lwjgl with vim and I'm trying to debug with jdb but I'm having some problems.

First of all I show you the tree of my project. (The main class is 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

I'm compiling my project with ant using the javac debug option. Here there is the part for the compilation in build.xml file:

<!-- Compile -->
<target name="compile">
    <mkdir dir="${classes.dir}" /> 
    <javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath" debug="true" includeantruntime="false" />
</target>   

The problem shows up when I'm trying to debug the application. I readed the man page and I saw that there is a classpath option. Since I'm using lwjgl I supose that I need to include the path to the .class files.

I'm executing this code form the root of the project.

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

I also noticed about this strange exceptions.

Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable

I found this post here that explains the solution.

ignore uncaught java.lang.Throwable

I'm not sure where I need to put this line of code in order to solve this. I also need to include the .class for lwjgl? I don't know what I'm doing wrong.

UPDATE:

I included lwjgl into my classpath and it's still now working well. I also included the path to my source files.

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

If I try to run JVM as a server of jdb the same error shows up.

Setting up JVM server

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

Connecting with 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

In the point when "Exception ocurred" the JVM shows up the same error.

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)

I see that there is a problem with the names but I don't know how to solve it.

When I run my jar file with lwjgl I need to attach the native files to the jar. I do this operation using ant. Here it is the target with I do this operation.

<!-- 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>    

Thank you for your time.

È stato utile?

Soluzione

To solve this problem I need to do 3 things.

  1. Specify the path to lwjgl.jar in the classpath.
  2. Add -Djava.library.path option for inserting the lwjgl natives.
  3. Use the full name of the class using also the package. Ex. com.ionsoft.engine.Engine

Here I add the working commands for ther JVM server and JDB client:

# JVM server
java -classpath ./build/classes:./lib/jars/lwjgl.jar -Djava.library.path=./lib/natives-linux -agentlib:jdwp=transport=dt_socket,address=localhost:8888,server=y,suspend=y com.ionsoft.engine.Engine

# JDB client
jdb -sourcepath ./src -connect com.sun.jdi.SocketAttach:hostname=localhost,port=8888

Hope that this help someone.

Altri suggerimenti

You need to include the lwjgl jar on the classpath.

Alternatively - and this may be easier - you can connect to another JVM using jdb, then I think the classes will be transported over the network or something. Or maybe they are just not needed.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top