In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to use the Java program of IntelliJ IDEA remote Debug Linux". In the daily operation, I believe that many people have doubts about how to use the Java program of IntelliJ IDEA remote Debug Linux. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubt of "how to use the Java program of IntelliJ IDEA remote Debug Linux". Next, please follow the editor to study!
Debug of 1 IDEA
Let's first take a look at what direct debug looks like in IntelliJ IDEA.
Prepare a simple Java program first:
Package com.pkslow.basic;import java.util.Map;public class RemoteDebug {public static void main (String [] args) {System.out.println ("- start-"); System.out.println ("get all the system environment"); Map envs = System.getenv () System.out.println ("\ nprint out the contains `HOME`"); System.out.println ("- env HOME-") Envs.entrySet () .stream () .filter (env-> env.getKey () .contains ("HOME")) .forEach (env-> {System.out.println (env.getKey () + ":" + env.getValue ());}) System.out.println ("- end-");}}
The function is simple: get all the system environment variables and print out the one with the HOME field.
Debug is simple, just click the following button:
I believe we all know this, but many people should not notice what IDEA has done and why it can be debugged. Let's take a look at the console log and we'll see:
/ Library/Java/JavaVirtualMachines/jdk1.8.0_212.jdk/Contents/Home/bin/java-agentlib:jdwp=transport=dt_socket,address=127.0.0.1:59313,suspend=y,server=n-javaagent:/Users/pkslow/Library/Caches/IntelliJIdea2019.3/captureAgent/debugger-agent.jar-Dfile.encoding=UTF-8-classpath "/ Library/Java/JavaVirtualMachines/jdk1.8.0_212.jdk/Contents/Home/jre/lib/charsets.jar:" com.pkslow.basic.RemoteDebugConnected to the target VM Address: '127.0.0.1 socket' 59313, transport:
To simplify, remove the unimportant parameters:
Java-agentlib:jdwp=transport=dt_socket,address=127.0.0.1:59313,suspend=y,server=n com.pkslow.basic.RemoteDebug
This is why it is possible to Debug, using the principle of Java Agent. This function is very powerful, similar to an AOP, a proxy Java program, you can use it for debugging, hot deployment, and so on.
2 debugging local programs
Let's first try how to debug local programs, not directly on IDEA. First compile the class file RemoteDebug.class, and then put it according to the package structure. I compile through mvn clean compile.
Start the program and execute it in the target/classes/ directory:
$java-agentlib:jdwp=transport=dt_socket,address=127.0.0.1:50050,suspend=y,server=y com.pkslow.basic.RemoteDebugListening for transport dt_socket at address: 50050
The program then waits for the debug client to connect and does not proceed.
Configure IDEA for debugging:
After the configuration is saved, click debug:
The program has entered debug mode:
Now that we have reached one of these lines, let's look at the server side:
It is synchronized with IDEA and has indeed controlled the execution of the server-side Java.
3Debug Linux Java programs remotely
First deploy the program on Linux:
$scp-P 22. / com/pkslow/basic/RemoteDebug.class root@xxx.xx.xx.xxx:/root/remoteDebug/com/pkslow/basic/RemoteDebug.class 100% 2572 282.5KB/s 00:00
Start the program on the server side with the following command, where the debug port is changed to 9999, because some of the ports are not open on the remote server:
Java-agentlib:jdwp=transport=dt_socket,address=9999,suspend=y,server=y com.pkslow.basic.RemoteDebug
The local computer IDEA is configured as follows:
Start debug, and normally control the Java of the remote server:
Real-time performance of the server:
Let the program finish as follows:
$java-agentlib:jdwp=transport=dt_socket,address=9999,suspend=y Server=y com.pkslow.basic.RemoteDebugListening for transport dt_socket at address: 9999-start-get all the system environmentprint out the contains `HOME`-env HOME-JAVA_HOME:/root/jdk1.8.0_131HOME:/root-end- -so far. The study on "how to use the Java program of IntelliJ IDEA remote Debug Linux" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.