16

I want to run my java code on a remote server for faster speed (The server is very powerful). What I want is to connect my Intellij to that remote server and run my code. But I want to still use the IntelliJ on my local machine (i.e. my laptop).

I found a config section in IntelliJ which is in Default Setting->Build-executation-deployment-> Deployment and there I can set the address of my remote server and username and password. But I don't know what to do next.

arghtype
  • 4,376
  • 11
  • 45
  • 60
HimanAB
  • 2,443
  • 8
  • 29
  • 43
  • Do you mean a remote web server with some Java EE container or do you want to run your plain java application there? In the first case see the answer from @arghtype, otherwise my answer is more suitable. – CrazyCoder Feb 22 '17 at 13:41
  • I mean running plain java on a remote server. Running my code on my laptop takes an age that's why I need to run it on our server which is a super powerful computer. What I want is to run my code using Intellij which is installed on my laptop and the code is actually run on that server. – HimanAB Feb 22 '17 at 13:45
  • Thanks, then please check my answer, it's exactly for your case. – CrazyCoder Feb 22 '17 at 13:46

2 Answers2

20

There is a step by step deployment guide for PhpStorm, but for IntelliJ IDEA it would be almost the same.

Here is the example configuration for deploying a .jar file from artifact subdirectory to the remote server via SFTP into /home/serge/artifact directory:

connection

mappings

I'd configure the artifact to produce the executable jar. Then adjust the deployment configuration to deploy the jar to the remote server. Or you can use Maven/Gradle to do the same.

Next, you can configure Remote SSH external tool to run the jar on the server (via java -jar jarname.jar:

remote ssh tool

Running on the remote server via Tools | External Tools | hello:

running

To automate the process enable Include in project build for the artifact, enable Automatic upload in Tools | Deployment and enable uploading of external changes in Tools | Deployment | Options.

To debug the code use Remote Debug configuration. Copy the JVM options needed for debug and adjust the options in your remote SSH external tool so that the app is started in debug mode and can accept connections (make sure firewall rules are adjusted to permit the connections on the specified port).

Community
  • 1
  • 1
CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • 1
    That guide, as you said, is for Php. Since this question might be for many other users as well, I appreciate if you could finalize your answer for java so that other users can also get their answer. So, what exactly is the process for Intellij? – HimanAB Feb 22 '17 at 13:49
  • I've updated the answer with the real examples for IntelliJ IDEA, deploying via SFTP and running using SSH external tool. – CrazyCoder Feb 22 '17 at 14:39
  • @HimanAB Is there anything else I can add so that you accept the answer? – CrazyCoder Feb 22 '17 at 17:27
  • I don't have access to my code at the moment so I honestly cannot test it right now to see if it works. I will definitely do so once I go home this evening. Thanks – HimanAB Feb 22 '17 at 18:00
  • Beautiful explanation. – lostsoul29 Jul 12 '17 at 19:18
  • Does this work for the community edition of intellij? – ThatDataGuy Jan 23 '19 at 15:13
  • @ThatDataGuy This feature requires IntelliJ IDEA Ultimate. – CrazyCoder Jan 23 '19 at 19:15
-1

If you need to debug your web application running on remote server you can do it this way:

Deploy your code to remote server. There are several ways to do it:

  • By intergration IDEA with you application server. Go into Settings > Build, Execution, Deployments > Application Servers and add your application server there. You could later use it as deployment target. See documentation.
  • By integration via you building tool, for example, maven have plugins for integration with many app servers. This works well when your build process is complicated.
  • Manually - simple copy build artifacts into target app server machine and deploy manually.

Connect to server in debug mode. To do this you need to create separate Run/ Debug configuration in IDEA. If you have Enterprise Edition you could choose configuration template for your server (e.q. Tomcat Server) and choose server from your Application Servers list. In Community Edition you have to use default Remote configuration instead.

When setup is done, your workflow should be the following:

  1. Make changes into code;
  2. Redeploy it into server (restart it if necessary);
  3. Run your debug configuration;
  4. Access your application on server (via browser for example) to trigger required code for execution;
  5. Debug
arghtype
  • 4,376
  • 11
  • 45
  • 60