I created a Java desktop-application (using Swing) and am now trying to make it work by starting it from the net using JNLP. The application works fine when I start it from the terminal, but as soon as I launch it from JNLP, it does not close. I have to manually kill the process every time.
I read that there might be a problem if my JFrame uses DISPOSE_ON_CLOSE as the default close-operation, but it doesn’t. It uses DO_NOTHING_ON_CLOSE (implicitly). Also, I’m explicitly calling System.exit(0) after releasing all my objects:
f = new JFrame("Pacman");
f.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// Terminate the Game-loop:
GameLoop.INSTANCE.stopLoop();
// Close the application:
System.exit(0);
}
});
I guess that there might be an exception thrown when I close the application, but I can’t find a way to get the console-output (e.g. the Stack-Trace) of a running application started with JNLP. Here’s what I tried:
- Start
javawswith the debugging parameters and connect withjconsole(works but I can’t find any exception- or console-ouput). - Start
javawswith the debugging parameters and attach IntelliJ debugger to it (also works but does not give me any output)
So, how can I start the application with JNLP and get the output (written to the default out- and error-streams), as if I would do with a normal desktop application?
Solution #1 – Enable Java Console, and look for exceptions.
You can do it via Java Control Panel. Switch to Advanced tab, and in the Java Console make sure Show console is selected.
Then, run your application and monitor the console for exceptions. Fix the exception.
Solution #2 – Debug your running application (properly).
Start the Web Start app like this (for Java 1.6 and newer):
If using earlier java versions (1.4.2, 1.5) set the environment variable, like this:
and run the app via:
When the app runs:
javaws(in this case:8123).windowClosingmethod.GameLoop.INSTANCE.stopLoop()method to see where/when it hangs.Don’t expect to see a solutions in the console, just step through the code with a debugger – if the application hangs, it will show you where.