aakarsh
aakarsh

Reputation: 320

What is the default properties that eclipse uses to launch a java process in its debugging mode?

I would like to connect to java process started by eclipse using a command line debugger but not sure what default properties of the eclipse launched java process are ? I wouldn't mind using attaching using sockets but not sure how much slower that would be ?

Upvotes: 3

Views: 368

Answers (2)

Abdull
Abdull

Reputation: 27852

I investigated on the differences of Java application startup in Eclipse between "Run" and "Debug". I used Sysinternals' Process Explorer to see the command line of the java process that Eclipse forks when starting a Java application with either option. (I'm on a Windows 7 system)

With "Run HelloWorld"

"C:\Program Files (x86)\Java\jdk1.7.0_07\jre\bin\javaw.exe" -Dfile.encoding=Cp1252 -classpath C:\workspace-juno\HelloWorld\bin com.example.HelloWorld

.......

With "Debug HelloWorld"

"C:\Program Files (x86)\Java\jdk1.7.0_07\jre\bin\javaw.exe" -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:2404 -Dfile.encoding=Cp1252 -classpath C:\workspace-juno\HelloWorld\bin com.example.HelloWorld

(The address port changed in succeeding invocations, e.g. it became address=localhost:2564 at the next invocation.)
So java (or javaw) actually gets started with different options depending on whether "Run" or "Debug" was used: the "Debug" start-up adds an additional agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:NNNN option. This is a standard way of putting a JVM into debuggable mode. The HelloWorld program will first wait for its debugger to successfully connect to it before continuing (option suspend=y). The HelloWorld JVM will connect itself automatically to some debugger running on address localhost:NNNN (... option address=localhost:NNNN and implicit default option server=n). (... Oracle provides authoritative information on the agentlib start-up options)

Eclipse itself will act as the debugger application providing a port NNNN. The HelloWorld JVM will connect to this port, via its own port of number NNNN+1 (one can see a process's used ports with Process Explorer on that process's TCP/IP tab).

Upvotes: 0

Ron
Ron

Reputation: 1952

how about

-Xdebug -Xnoagent -agentlib:jdwp=transport=dt_socket,suspend=n,address=localhost:12345

then you can attach a java debugger to port 12345

Upvotes: 2

Related Questions