views:

3263

answers:

4

I found a bug in an application that completely freezes the JVM. The produced stacktrace would provide valuable information for the developers and I would like to retrieve it from the Java console. When the JVM crashes, the console is frozen and I cannot copy the contained text anymore.

Is there way to pipe the Java console directly to a file or some other means of accessing the console output of a Java application?

Update: I forgot to mention, without changing the code. I am a manual tester.

Update 2: This is under Windows XP and it's actually a web start application. Piping the output of

javaws jnlp-url
does not work (empty file).

+4  A: 

(If you can modify the code) you can set the System.out field to a different value:

System.out = new PrintStream(new FileOutputStream(fileName));

If you are running a script (invoking the program via java) from Unix you could do:

/path/to/script.sh >& path/to/output.log
oxbow_lakes
Sorry, I forgot to mention: Without touching the code. Mea culpa!
Ced
Hmm. `System.out` is `final`, so you can't change it like that to use `PrintStream`.You could use `System.setOut(...)` to do that, i.e.:`System.setOut(new PrintStream(new FileOutputStream(fileName)));`
Allen George
+2  A: 

A frozen console probably means a deadlock (it could also mean repeated throwing of an exception). You can get a stack dump using jstack. jps may make finding the process easier.

Tom Hawtin - tackline
+12  A: 

Actually one can activate tracing in the Java Control Panel. This will pipe anything that ends up in the Java console in a tracing file.

The log files will end up in:

  • <user.home>/.java/deployment/log on Unix/Linux
  • <User Application Data Folder>\Sun\Java\Deployment\log on Windows
Ced
Just found this nice solution, thanks for the support, guys!
Ced
+1. I was just about to add this answer.
Mark
Can you tell us why the console froze?
Tom Hawtin - tackline
Not really, I don't understand the stack trace all to good, as I am not a developer on this team. As far as I can tell, it is related to painting some components and the event-dispatch thread (as usual, haha).
Ced
@Ced: You should mark this as accepted.
James Van Huis
Yup, I will do that, James. It's just that the system does not let you do that before 48 hours have passed.
Ced
Ah, I see. I was unaware.
James Van Huis
A: 

When I found a crash in a Java application I tried to get some help from the above thread (which started a year ago). In my case I run GeoGebra.exe (from GeoGebra.org) and the program crashes (total freeze-up) when I either Apply Ctrl-C to a dialog used for renaming a label, or when I apply Ctrl-C to any line in the Java console. I have examined the log files in Application Data/Sun/deployment/log, but there is nothing added to these when the crash occurs. I suspected at first a fault in XP, but a repair re-install makes no difference. I guess there is a bug in the program (doubtful) or some crazy conflict with something else.

Has anyone any real solution to this issue ?

On Vista there is no problem !

RaymondM