Reputation: 320
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
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
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