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. Bu
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:
Settings > Build, Execution, Deployments > Application Servers and add your application server there. You could later use it as deployment target. See documentation.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:
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:
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:
Running on the remote server via Tools | External Tools | hello:
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).