Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The principle of remote deployment and debugging of java

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "the principle of remote deployment and debugging of java". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Remote debugging is very useful, especially when you are developing locally and you need to debug programs on the server.

JAVA supports debugging, and provides a simple debugging tool JDB, which supports setting breakpoints and thread-level debugging. at the same time, different JVM contacts through the interface protocol, and local Java files establish contact and communication in the remote JVM. This article is a summary of Intellij IDEA remote debugging tutorials and principle explanation, know what it is and why. Remote deployment Click

1. Native Intellij IDEA remote debugging configuration

1. Open Inteliij IDEA, and select Run- > Edit Configurations in the top menu bar to enter the run / debug configuration interface of the following figure.

2. Click the'+ 'sign in the upper left corner and select Remote. Fill in the parameters in the three red boxes on the right: Name,Host (the remote debug port you want to specify).

3. Click the apply button in the lower right corner of the interface.

two。 Debug mode is enabled on the server side, and JVM startup parameters are added to support remote debugging

Server-side catalina.sh file, in the Tomcat installation directory, copy to the local, edit, in the first line to add parameters configured as follows, paste back after completion.

Text:

CATALINA_OPTS= "- Xdebug-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8089"

After the configuration is added, restart tomcat will take effect (shutdown.sh / startup.sh). At this point, start remote debugging.

3.Intellij IDEA initiates a remote call

Finally, open IDEA, make a breakpoint on the program, select remote running mode, and click run. Call the system program running on the server side, and the system automatically enters the breakpoint.

4. Why is it possible to debug remotely and what is the principle behind it?

First of all, understand the execution process of the Java program-divided into the following steps: Java file-compiled generated class file (class file)-JVM load class file-JVM run class bytecode file-JVM translator translates into different machine codes recognized by each machine.

Principle of remote debugging

As we all know, the Java program runs on the Java virtual machine (JVM) and has a good cross-platform, because the Java program runs in JVM in the form of bytecode, and the virtual machines on different platforms all use the same program storage format. Because they are all class bytecode files, as long as the local code and the class file on the remote server are the same, the two JVM communicate through the debugging protocol (for example, communicating on the same port through the socket). In addition, it should be noted that the server being debugged needs to turn on debug mode, and the server-side code must be consistent with the local code, which will cause the breakpoint to be inaccessible.

Debugger architecture of Java

1. The essence of this architecture is JVM. As long as you ensure that the source code of the local Java is consistent with the target application, the source code of the local Java can be connected to the remote JVM through a socket, and then debug. Therefore, in this socket connection mode (described below), only the local source code is needed, and the local Java application does not need to be started at all.

Transmission method. Default is Socket.

Sockets: MACOS,Linux systems use this mode of transmission

Shared memory: this transfer is used by WINDOWS systems.

Debug mode: default is Attach

Attach: in this mode, the debugging server (the machine being debugged remotely) starts a port waiting for us (the debugging client) to connect

Socket: in this mode, we (the debug client) listen on a port and connect when the debug server is ready.

Configuration property description supplement

Text:

CATALINA_OPTS= "- Xdebug-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8089"

two。 The parameters are explained:

-Xdebug: tells JVM to work in debug mode-Xrunjdwp: tells JVM to use (java debug wire protocol) to run the debug environment. The parameter also has a series of debugging options: session: specifies the transmission mode of debugging data. Dt_socket refers to SOCKET mode, and dt_shmem refers to shared memory mode, in which dt_shmem is only applicable to window platform.server parameter refers to whether it is supported in virtual machines in server mode. Onthrow: indicates that when an exception of this type is generated, the JVM will be interrupted and the parameter will be optionally modulated. Release: indicates the executable program to be executed when JVM is interrupted. This parameter is optional suspend.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report