Search code examples
javalinuxeclipsedebuggingremote-debugging

Java remote debugging on linux target using Eclipse or otherwise


Can anyone tell me a good approach to remote debugging Java on linux targets?

What I'm after is some method to build my Java project, deploy to target and then debug on the target. I know java can debug on target by starting the running JAR with debug flags e.g.

java -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y suspend=y -jar stockTradingGUI.jar

But I don't know how to trigger the deployment of built JAR to the target and running in debug mode through Eclipse.

Does anyone have any ideas?

Thanks


Solution

  • With Eclipse itself, one generally wouldn't try to do the deployment of the built JAR to the target and have it run in debug mode. Instead, one would start the remote debugging session in Eclipse after having deployed the newly built jar and started it with the various debug/suspend flags to allow you to remotely connect to it.

    There are a variety methods of doing the deploy.

    The most straightforward would be to simply do a regular built in Eclipse (or at the command line via ant or using whatever build tool you are using), manually scp the jar over to the remote location, and ssh into the box and start the app up using the necessary commands.

    Another option is to use a deployment framework such as fabric (written in Python) which will do the build, scp it over to your remote location, and then run whatever commands you need to run in order to get that up and running (i.e. first stopping an existing Tomcat instance, etc. or whatever the case may be). You can have different environments setup in the fabfile, such as debug and prod, so you can deploy it in debug mode for cases like you are looking for now, and then in prod mode it deploys normally and just runs.

    If you are using Gradle, it has some tools such as Cargo that can help with remote deployments, or for simpler use cases, using the ssh plugin and managing things more directly (see http://java.dzone.com/articles/replace-your-scripts-gradle for more details).

    Edit in response to comment from OP:

    I've not used Remote System Explorer myself, but it appears to be extensible to some extent (see the Service and Subsystem layers), although fundamentally it still seems to be UI-focused.

    For this sort of use case I would recommend giving Gradle another look, as it's focused on building, is very extensible, and can be integrated into Eclipse or run completely on the command line.