简体   繁体   中英

How to debug a runnable jar, when crash doesn't happen in debugger?

When I debug the game in eclipse the game works fine. However, when I make runnable jar out of it the game crashes when enemy gets hit, the rest of the game works fine except that part. What do I do, how do I debug runnable jar?

Put a try/catch around the function where an enemy gets hit. In the catch statement, have it print a stack trace and information on the exception caught.

Something like:

try {
   enemyHit();
} catch (Exception e) {
    System.out.print("RuntimeException: ");
    System.out.println(e.getMessage());
    e.printStackTrace();
}

Run the jar from the command line so that the printouts are still there when the jar crashes. Alternatively, write the error information to a file.

You can put the try/catch further up the stack if this doesn't catch anything. If you're not catching exceptions anywhere else, you can put this try catch all the way at the top of your stack surrounding your main loop.

I wouldn't recommend keeping the try/catch in your release code if you're fairly sure the bug is solved. There are performance issues associated with try/catch that will slow down your game if you have them surrounding frequently accessed functions.

create a new project and add the runnable jar to the external jars, then using the run configurations you can select it's main method and debug from there

you can also set the source folder of the jar to the source folder of the other project (just remember that the hot code replace doesn't work anymore)

when i have had an issue similar to you are seeing it is down to the debugger taking a little extra time (especially with break points) then the compiled program.

this issue occurred when i was trying to load a texture asyncronously it would work fine in the debugger but crash when compiled, i would look into any threading (if you have any) or any other longer running item

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM