Tuesday, May 27, 2014

Java remote debug to linux

1. On linux side, no need to configure anything (For JConsole, need config iptables)
2. Compile the application with the debug options, for gradle, add the below (may use javap to verify)
compileJava.options.debugOptions.debugLevel = "source,lines,vars"
3. add -Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=y to start the Java application
4. From Eclipse, create a new remote Java application in the debug configuration for the app
5. When the Java application suspends on linux (the message would like "Listening for transport dt_socket at address: 4000"), run the debug from PC eclipse
~~~ enjoy

For maven:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<debug>true</debug>
                                       <debuglevel>lines,vars,source</debuglevel>
</configuration>
</plugin>