Experience IntelliJ IDEA's remote development (Remote Development)

Overview of this article

  • IDEA's remote development function can put local compilation, construction, debugging, operation and other work on the remote server, while only running the client software locally for regular development operations. The official logic diagram is as follows, It can be seen that the local computer and server are connected through the local IDE and the IDE backend on the server to achieve the effect of remote development.

image-20220319174602803

  • In actual experience, it feels like ordinary IDEA local development, but in fact the heavy tasks are handed over to the server. For local computers with poor performance, applications that could not run before can now be run with powerful servers. Can run smoothly

  • Let’s practice IDEA remote development today, so that even a dilapidated local computer can compile and run Java applications smoothly.

  • The article consists of the following paragraphs:

  1. Environmental information at a glance
  2. Prepare server
  3. IDEA remote connection
  4. Reset the project root directory
  5. port forwarding
  6. Other things to note

Environmental information at a glance

  • The following is the environmental information of my actual combat here, which can be used as a reference.
  1. IDEA:2021.3.2 (Ultimate Edition)
  2. Local computer operating system: macOS Montery (12.3)
  3. Server: Ubuntu 20.04 LTS (4 cores 8G)

Prepare server

  • A Linux server is necessary for remote development. It can be used on your own intranet or rented from a cloud service provider.

  • IDEA will automatically install the required services on the server. We don’t need to prepare anything in advance. The only requirement is that we can log in to the server through SSH.

  • Xinchen's server is Tencent Cloud Light Application Server, rented from the official website, as shown below, 4 cores 8G, costing more than 200 a year, which feels quite cost-effective

    Insert image description here

  • Next, we need to prepare the development code on the server. I downloaded my github repository to the server and the code is stored here: /home/ubuntu/ jetbrains-workspace

<span style="color:#393939"><span style="background-color:#faf7ef"><code class="language-java">ubuntu<span style="color:#2b91af">@VM</span>-<span style="color:#880000">12</span>-<span style="color:#880000">12</span>-ubuntu:~/jetbrains-workspace$ git clone https:<span style="color:#008000">//github.com/zq2599/blog_demos.git</span>
Cloning into <span style="color:#a31515">'blog_demos'</span>...
remote: Enumerating objects: <span style="color:#880000">14559</span>, done.
remote: Counting objects: <span style="color:#880000">100</span>% (<span style="color:#880000">1097</span>/<span style="color:#880000">1097</span>), done.
remote: Compressing objects: <span style="color:#880000">100</span>% (<span style="color:#880000">350</span>/<span style="color:#880000">350</span>), done.
remote: Total <span style="color:#880000">14559</span> (delta <span style="color:#880000">846</span>), reused <span style="color:#880000">818</span> (delta <span style="color:#880000">703</span>), pack-reused <span style="color:#880000">13462</span>
Receiving objects: <span style="color:#880000">100</span>% (<span style="color:#880000">14559</span>/<span style="color:#880000">14559</span>), <span style="color:#880000">110.29</span> MiB | <span style="color:#880000">3.05</span> MiB/s, done.
Resolving deltas: <span style="color:#880000">100</span>% (<span style="color:#880000">4714</span>/<span style="color:#880000">4714</span>), done.
</code></span></span>

IDEA creates a remote connection

  • After the server side is prepared, the remote connection operation of the local computer can be started.

  • Open IDEA, as shown below, select New Connection

image-20220319101341382

  • Enter IP address, account password

    Insert image description here

  • Enter the password as required. After the remote connection is successful, specify the working directory (Project directory). I specified the directory where the code warehouse is located, and then click Download and Start IDE in the lower right corner.

    Insert image description here

  • The remote server starts downloading the backend application, which is a service used to support remote development

    Insert image description here

  • After waiting for the download to complete, there will be an additional application called JetBrains Client , which has been opened, as shown in the red box below. This is the local tool for remote development in the future.

image-20220319155712297

  • The JetBrains Client interface is as follows. It looks like IDEA. You can see the contents of the entire warehouse just downloaded from the server. It is no different from opening it locally. The Terminal opens the server directory. When modifying the code, the code on the server is also changed.

    Insert image description here

  • There is one question left: as shown in the picture above, there is not only one java project in this warehouse, but dozens of folders, each folder is an independent project (some are gradle, some are maven), if I now I only want to modify one of them (such as quarkus-tutorials in the red box above ), compile and run it, what should I do? Next, we will solve this problem (this is an IDEA operation, not a remote connection problem)

Reset the project root directory

  • The next problem to be solved is: there are multiple projects in the folder opened remotely by the IDE, and I only want to open one of the maven projects for development and debugging.

  • Select "File" -> "Project structure..." from the top menu

image-20220319112034629

  • Clicking the X symbol in the red box in the picture below will delete the current content root directory (Content Root)

    Insert image description here

  • Click the plus sign in the red box below to re-add the content root directory (Content Root)

    image-20220319112529312

  • Just select the folder used for development

image-20220319112753819

  • After selecting, you finally see the familiar directory structure

image-20220319113217415

  • You may feel that the operation in this section is unnecessary: ​​just set the working directory to quarkus-tutorials when connecting remotely . There is no need to go to such trouble. You are right, you can indeed specify the directory directly when connecting remotely. But if you are using Jetbrains space at the moment, you cannot directly specify the directory there, you can only open it directly.

Run as a maven project

  • Regarding the JDK of the server, if it is installed, please select it according to the location in the picture below. If it is not installed, just download it remotely according to the picture below.

image-20220319113425220

  • At this moment, the IDE does not recognize that this is a maven project. You need to open pom.xml, and then select Add as Maven Project in the right-click menu , as shown in the red box below

image-20220319115056364

  • After waiting for the project to be loaded and updated (it takes a long time to generate the index, half an hour here), I finally saw the familiar maven project page, which is no different from when using IDEA.

    image-20220319121939312

  • Try maven's unit test, as shown below. It is no different from using IDEA and executes smoothly.

image-20220319153835111

port forwarding

  • When developing web applications, it may be troublesome to access remote IP addresses and ports after starting the application (some servers do not easily open ports due to security issues). At this time, the port forwarding function provided by JetBrains Client is very practical.
  • The port forwarding configuration is as shown below, so that when I access port 8080 of this machine, the request will be forwarded to port 8080 of the server.

image-20220319121633425

  • Try starting the application. My application is an ordinary web application. After startup, it listens to port 8080. However, I did not open port 8080 for the server to the external network. As shown below, it can be accessed successfully from the local area.

    Insert image description here

Other things to note

  • When exiting, you will be prompted whether to close the remote service. Please make your own choice. I chose Close and Keep Running.

image-20220319104230126

  • If you find it troublesome to enter your password every time, just save it in idea.

image-20220319104609627

  • The previous records will appear the next time you open them, click to enter

    Insert image description here

  • The Git submission function can also be used normally: local submission is actually submitting the code on the server to Github

    Insert image description here

  • Finally, don’t forget to go to the plug-in management page to install commonly used plug-ins.

  • At this point, the actual experience of IDEA remote development has been completed. I hope this article can give you some reference to help you build a stable and high-performance development environment.

Guess you like

Origin blog.csdn.net/2301_78834737/article/details/132004664