Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij IDEA remotely debug java console program

I have a remote server with Java running to which i have SSH access. I am writing an app on the local machine, building it with maven. Is it possible to set the IDE Itellij IDEA to run my project remotely? The idea is : to build the jar, copy it to the server, and debug the process ( or something like that).

It would be nice of you to share the settings i need to setup.

like image 615
Dmitrii G. Avatar asked Apr 28 '15 10:04

Dmitrii G.


People also ask

What is remote JVM debug in IntelliJ?

Remote Debugging with IntelliJ IDEAUltimate. Last modified: 21 July 2022. With IntelliJ IDEA you can debug your application using an interpreter that is located on the other computer, for example, on a web server or dedicated test machine. IntelliJ IDEA provides two ways to debug remotely: Through a remote interpreter ...

How do I enable remote debugging in Java?

Enable JVM DebuggingClick the Configurations tab to see the list of available configurations and select the configuration you need. Click Java > JVM Settings tab. Under Debug Java Settings, select the Enable Debug checkbox. Provide JVM options as necessary by clicking the New button.

How do I run a Java program in debug mode?

A Java program can be debugged simply by right clicking on the Java editor class file from Package explorer. Select Debug As → Java Application or use the shortcut Alt + Shift + D, J instead. Either actions mentioned above creates a new Debug Launch Configuration and uses it to start the Java application.

How do I debug in IntelliJ terminal?

Run the program in debug modeClick the Run icon in the gutter, then select Modify Run Configuration. Enter arguments in the Program arguments field. Click the Run button near the main method. From the menu, select Debug.


1 Answers

This is what I usually do to debug my remote app.

  1. Run the server on debug mode

    This can be adding this particular line when you run your application server

    -Xdebug -Xrunjdwp:transport=dt_socket,server=n,suspend=n,address=9999
    

    for JDK above 1.4, you can use this

    -agentlib:jdwp=transport=dt_socket,server=n,suspend=n,address=9999
    

    After that, run your application server

  2. SSH Tunneling

    I'm not 100% sure that you can access to your application's port directly if you're using ssh connection (well, maybe there is a way ;) ). So, first we need to expose the port for debugging that we set on first step by running this command.

    ssh -f [email protected] -L 9999:personal-server.com:9999 -N
    
  3. Setting up the IDE

    You can follow the step that @SSJVegito has said, which basically, is to point the debugger to the port 9999. Open the debug configuration in your Idea, then Change the circled value to 9999. Then, happy debugging :D debug configuration

like image 83
kucing_terbang Avatar answered Sep 18 '22 01:09

kucing_terbang