10

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.

Dmitrii G.
  • 895
  • 1
  • 7
  • 21

2 Answers2

15

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 user@personal-server.com -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

kucing_terbang
  • 4,991
  • 2
  • 22
  • 28
  • 1
    I was able to get it working but things like getting thread dump are extremely slow and freeze the application while I wait for them to finish. The application freezing for more than a second is not acceptable for me. Any idea what can I do to fix it? – barteks2x Aug 20 '17 at 18:30
1

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.

  • I probably misunderstand something, but why do i need the Tomcat to run a simple server side "hello world" console program. I also didn't find any mention of ssh connection to the remote server. – Dmitrii G. Apr 28 '15 at 11:07
  • I've used tomcat as an example server. My Tomcat is the server to which you are connected via SSH. However, what I've told you applies for applications which are deployed on that server, e.g. web archives (.war files). I'm not sure that what you are requesting can be done for .jar files (or at least, I've never encountered such a scenario). Either way, this is the way in which you connect to a remote server in order to debug you application from IntelliJ. –  Apr 28 '15 at 11:11