Dmitrii G.
Dmitrii G.

Reputation: 895

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.

Upvotes: 10

Views: 11725

Answers (2)

kucing_terbang
kucing_terbang

Reputation: 5131

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

Upvotes: 15

user4655581
user4655581

Reputation:

I think it's possible, I was able to do such a thing with a local server I was using to deploy my application. And since you have access to the server, it should work for you as well.

What you need to do in IntelliJ is create a Remote configuration. To do that, open IntelliJ and next to the run button (on the left), you should have your configurations, designated by a down arrow. Click that arrow and click Edit Configurations. A new window should open. Click the + sign in the upper left corner and the select Remote. A new window should appear. We now need to set the host and the port which the server uses for debugging (if you are using tomcat, it is usually 8000; in tomcat, you can locate it by opening the catalina.bat file with a text editor and looking for the JPDA_ADDRESS property, which allows you to change the port). Give your configuration a name and press Apply.

Afterwards, you need to run your configuration in Debug mode. You need to select it from the configuration list and press the Debug button located to the right of the Run button.

More details here:

http://blog.trifork.com/2014/07/14/how-to-remotely-debug-application-running-on-tomcat-from-within-intellij-idea/comment-page-1/

http://eclipse.org/jetty/documentation/current/debugging-with-intellij.html

http://www.javaranch.com/journal/200408/DebuggingServer-sideCode.html

I hope this helps.

Upvotes: 1

Related Questions