In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
In this issue, the editor will bring you about the process of IDEA remote deployment and debugging Java applications. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.
Basic overview
In our work, we may encounter that we cannot connect to resources such as the development environment database locally, but we also want to develop and debug directly locally.
At this point, you can pass the Run on of IDEA. Function realization.
Its principle is to connect to the remote server through SSH, deploy the application to the remote server, and connect locally to the application deployed by the remote server.
PS: this operation is much more secure than building a proxy service on a remote server.
Prepare to work the remote server prepares to install JDK [root @ switch-sz-service-test ~] # yum install-y java-1.8.0-openjdk-devel.x86_64# you can see that the version of Java is 1.8 [root@switch-sz-service-test ~] # java- versionopenjdk version "1.8.0 OpenJDK Runtime Environment (build 1.8.0_302-b08) OpenJDK 64-Bit Server VM (build 25.302-b08) Mixed mode) configure JAVA_HOME# to see that JAVA_HOME is / usr/lib/jvm/java-1.8.0-openjdk-1.8.0.302.b08-0.el8_4.x86_64 [root@switch-sz-service-test ~] # find /-name java/etc/pki/ ca-trust/extracted/java/etc/pki/java/etc/alternatives/java/etc/java/var/lib/alternatives/java/usr/bin/java/usr/lib/ Java/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.302.b08-0.el8_4.x86_64/jre/bin/java/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.302.b08-0.el8_4.x86_64/bin/java/usr/lib/jvm/java/usr/share/bash-completion/completions/java/usr/share/java [root@switch-sz-service-test ~ ] # ll / usr/lib/jvm/java-1.8.0-openjdk-1.8.0.302.b08-0.el8_4.x86_64total 180 RW Jul 22 01:18 ASSEMBLY_EXCEPTIONdrwxr-xr-x 2 root root 4096 Oct 4 00:29 bindrwxr-xr-x 3 root root 0.el8_4.x86_64total 4 00:29 includedrwxr-xr-x 4 root root 95 Oct 4 00:29 jredrwxr-xr-x 3 root root 144th Oct 4 29 lib-rw-r--r-- 1 root root 19274 Jul 22 01:18 LICENSEdrwxr-xr-x 2 root root 204 Oct 4 00:29 tapset-rw-r--r-- 1 root root 155003 Jul 22 01:18 THIRD_PARTY_README# configuration JAVA_ Home [root @ switch-sz-service-test ~] # vim / etc/profile# add the following statement JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1 at the end. 8.0.302.b08-0.el8_4.x86_64export JAVA_HOME# can see that JAVA_HOME has been configured [root@switch-sz-service-test ~] # source / etc/profile [root@switch-sz-service-test ~] # echo $JAVA_HOME/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.302.b08-0.el8_4.x86_64 [root@switch-sz-service-test ~] # project ready to create a SpringBoot project
To create a SpringBoot project using Spring Initializr, refer to the project: springboot-remote-deploy-demo
Create a Controller class package com.switchvov.springboot.remote.deploy.demo.controller;import lombok.extern.slf4j.Slf4j;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController / * @ author switch * @ since 2021-10-3 * / @ RestController@RequestMapping ("/ hello") @ Slf4jpublic class HelloController {@ GetMapping ("/ {name}") public String hello (@ PathVariable ("name") String name) {String hello = "hello" + name; log.info (hello); return hello;}} launch the application and verify the result package com.switchvov.springboot.remote.deploy.demo;import org.springframework.boot.SpringApplication Import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class SpringbootRemoteDeployDemoApplication {public static void main (String [] args) {SpringApplication.run (SpringbootRemoteDeployDemoApplication.class, args);} $curl http://127.0.0.1:8080/hello/worldhello world%
PS: from the steps above, you can see that it has been successfully executed locally, and the next step is to have him deployed remotely to the server and can be debugged.
Apply configuration modify application configuration
Right-click the launcher next to the SpringbootRemoteDeployDemoApplication class, pop up the option box, and click Modify Run Configuration... Option, the pop-up interface is as follows
Create a remote server
Left-click the Run on option box, pop up the option box, and click SSH... Option, the pop-up interface is as follows
Enter the server address Host, user name Username, click the Next button, and the jump screen is as follows
Enter the password Password (or use the key) and click Next to jump the screen as follows
This step is mainly to verify whether you can log in to the server and whether the basic environment on the server is installed. Click Next to jump to the screen as follows
Successfully connected to root@120.78.218.44:22 > pwd/rootCommand finished with exit code 0Checking rsync connection.../usr/bin/rsync-n-e "ssh-p 22" root@120.78.218.44:root@120.78.218.44's password: dr-xr-x--- 190 00:56:11 on 2021-10-04. Process finished with exit code 0Starting introspection for Java... > echo ${SHELL} / bin/bashCommand finished with exit code 0 > echo ${ JAVA_HOME} / usr/lib/jvm/java-1.8.0-openjdk-1.8.0.302.b08-0.el8_4.x86_64Command finished with exit code 0 > java- versionopenjdk version "1.8.0o302" OpenJDK Runtime Environment (build 1.8.0_302-b08) OpenJDK 64-Bit Server VM (build 25.302-b08 Mixed mode) Command finished with exit code 0Introspection completed
You can see that the project deployment path, Project path on target,JDK Home path, JDK home path and JDK version JDK version have been set up. Click Finish to return to the previous interface
PS: you can modify configurations such as deployment paths yourself.
Save application configuration
You can see that the remote server has been configured. Click the OK button to complete the configuration.
Verification result local verification
Click the SpringbootRemoteDeployDemoApplication startup button, and you can see that it has been deployed to the server in the startup log, and you can also see that the local port 63006 is mapped to the server's port 8080.
$curl http://localhost:63006/hello/worldhello world%
Local access to port 63006 mapped to the server can also be accessed normally.
PS: it can be started or debugged, of course.
Server authentication
On the remote server, you can see that springboot-remote-deploy-demo has been deployed under the / root path, and accessing http://127.0.0.1:8080/hello/world will return hello world correctly.
[root@switch-sz-service-test ~] # pwd/root [root@switch-sz-service-test ~] # lltotal 4drwxr-xr-x 38 root root 4096 Oct 4 01:08 springboot-remote-deploy-demo [root@switch-sz-service-test ~] # curl http://127.0.0.1:8080/hello/worldhello world [root@switch-sz-service-test ~] # this is the process of remote deployment and debugging of Java applications shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.