Deploy / debug Java code on a remote server using Intellij

I want to run my Java code on a remote server for more speed (the server is very powerful). I want to connect my Intellij to this remote server and run my code. But I want to use IntelliJ on my local machine (i.e. on my laptop).

I found the configuration section in IntelliJ, which is located in Default Setting->Build-executation-deployment-> Deployment , and there I can set the address of my remote server, username and password. But I do not know what to do next.

+4
source share
2 answers

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

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

connection

mappings

I would set up an artifact to create an executable banner . Then configure the deployment to deploy the jar to the remote server. Or you can use Maven / Gradle to do the same.

Then you can configure the Remote External SSH Application to run the banner on the server (via java -jar jarname.jar :

remote ssh tool

Work on a remote server through Tools | External Tools | hello :

running

To automate the process, turn on Include in the project assembly for an artifact, enable Automatic upload in Tools | Deployment and enable uploading external changes to Tools | Deployment | Options

To debug code, use Remote Debugging Setup . Copy the JVM parameters necessary for debugging and edit the parameters in the remote external SSH tool so that the application runs in debug mode and can accept connections (make sure that the firewall rules are configured to allow connections on the specified port).

+6
source

So you need to do two things:

Deploy the code on the remote server. There are several ways:

  • By integrating IDEA with your application server. Go to Settings > Build, Execution, Deployments > Application Servers and add your application server there. Subsequently, you can use it as a deployment target. See the documentation .
  • Thanks to integration with the build tool, for example, maven has plugins for integration with many application servers. This works well when the build process is complicated.
  • Manually β€” Simple copies of copy artifacts to the target application server and manual deployment.

Connect to the server in debug mode. To do this, you need to create a separate Run / Debug configuration in IDEA. If you have an Enterprise Edition, you can select a configuration template for your server (eq Tomcat Server) and select a server from the list of applications. In Community Edition, you must use the default Remote configuration.

When setup is complete, your workflow should be as follows:

  • Make changes to the code;
  • Reinstall it on the server (restart it if necessary);
  • Run the debug configuration;
  • Access to your application on the server (for example, through a browser) to run the required code to execute;
  • Debug
-1
source

Source: https://habr.com/ru/post/1268516/


All Articles