Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java/Eclipse: starting a new JVM in Debug mode

Is it possible for my Java program to start a 2nd JVM (via ProcessBuilder for instance running javaw.exe) in Debug mode so it appears in Eclipse's debug window?

If so, how?

like image 752
Jason S Avatar asked Apr 19 '11 14:04

Jason S


People also ask

How to debug a remote Java application in JVM?

n order to debug a remote Java application, it should be launched with some extra arguments to instruct the JVM to execute it in debug mode. This is done as follows: The above command tells the JVM to start the application sampleApp.jar while having a server socket listening at port 8000 for a debugger to attach to it.

How to run eclipse debugger on a remote application?

The suspend argument tells whether you want the JVM to wait until a debugger attaches to the port number before the application effectively runs. After launching the remote application with the above parameters, the next step is attach your Eclipse debugger to the remote application. This is done as follows: Go to Run > Debug Configurations...

Which IDE do you use to debug your java application?

Last modified on August 1st, 2014 by Joe. Debugging a remotely running Java application using Eclipse IDE is an important skill in our Java debug arsenal. Eclipse IDE is what I use mostly and so I took it for example.

How do I launch a Java program and connect the debugger?

The specific technique for launching the program and connecting the debugger is VM-specific. The basic steps are as follows: Ensure that you are building your Java program with available debug information.


1 Answers

A possible way to achieve what you (possibly) want: enable the second jvm for remote debugging. As far as I remember, you can tell the jvm to wait until the remote debugger is hooked to the session. Then, after that "child jvm" is spawned, start a remote debugging session in eclipse.

This is the set of parameters for a classic VM:

java -Xdebug -Xnoagent -Djava.compiler=NONE 
     -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 ...

(suspend=y tells the jvm to wait for the debugger, 5005 is the port in this example)

Starting from JavaSE 1.5, these were replaced with a standardized parameter:

java -agentlib:jdwp=transport=dt_socket,address=localhost:9009,server=y,suspend=y
like image 113
Andreas Dolk Avatar answered Oct 21 '22 10:10

Andreas Dolk