Describes how IntelliJ IDEA can remotely debug Tomcat, intellijtomcat
Said the blogger: To better locate and solve problems during code debugging, we sometimes need to use remote debugging. In this article, let's take a look at how to use IntelliJ IDEA to debug remote Tomcat.
First, configureremote
:
As shown in, clickEdit Configurations
To go to the following page:
As shown in, we enterRun/Debug Configurations
Interface, and then click+
, SelectRemote
:
- Note 1: Run the command line parameters of the remote JVM;
- Note 2: Transmission mode. The default value is
Socket
;
- Mark 3: Debugging mode. The default value is
Attach
;
- Note 4: Server IP address. The default value is
localhost
To change the IP address of the target server;
- Mark 5: Server port number. The default value is
5005
, You need to change it to the real Port Number of the target server;
- Note 6: The Search resource is the environment variable used. The default value is
<whole project>
, That is, the entire project.
As shown in, whereNote 2AndMark 3There are two typesNote 2,
- Note 2: Transmission mode. The default value is
Socket
;
Socket
: This transmission mode is used in macOS and Linux systems;
Shared memory
: This transmission mode is used in Windows.
ForMark 3,
- Mark 3: Debugging mode. The default value is
Attach
;
Attach
: In this mode, the debugging server (the machine that is remotely debugged) starts a port and waits for us (the debugging client) to connect;
Listen
: In this mode, we (the debugging client) listen to a port. When the debugging server is ready, it will connect.
Then, copyNote 1That is, the command line parameters automatically produced by IntelliJ IDEA are imported to the Tomcat configuration file. Taking Linux as an example, the import statement is:
export JAVA_OPTS='-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8001'
For Windows systems, the import statement is:
set JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8001
The difference between the two is that the keywords of the Import Statement are different and there are no quotation marks. in Linux, the import keyword isexport
, Windows isset
The Linux import value must be enclosed in single quotes.''
While Windows does not.
Next, modifycatalina.sh
File (if it is a Windows system, modifycatalina.bat
File), add the preceding import statement to this file:
Now, IntelliJ IDEA has completed the remote debugging of Tomcat, and the subsequent debugging steps can be done according to the normal debugging skills!
+++ Digress: I am a big egg.
Here, we assume that the IP address of the server is10.11.12.39
, The port number is16203
, EnterDebug
Mode. If the connection is successful, the following prompt is displayed:
In addition, if debugging is performed across multiple systems, you only need to configureRemote
, Hitting the breakpoint, startDebug
Mode, and then execute the program at the beginning of the Service to enter the breakpoint we set. In addition, if we configureRemote
And associate it with a Tomcat.Debug
All functions that involve the Code where the breakpoint is located will go to the breakpoint we set.
For example, for Tomcat A on the server, multiple systems use This Tomcat, such as the order subsystem, account subsystem, and routing subsystem, and multiple systems call each other, if the order sub-system calls the account sub-system and the account sub-system calls the routing sub-system, when we configureRemote
And the corresponding code (for example, to query the merchant's account information in the order subsystem, it is transferred to the account subsystem; place a breakpoint on the account sub-system and transfer it to other underlying services to query the account balance of the merchant.Debug
After the mode is enabled, the Order sub-system's account information query function is triggered through unit tests or page operations, and the breakpoint set in the above three sub-systems will be entered in turn.
In addition, after we configure remote debugging, even if someone else starts the relevant service, it will go to our breakpoint and be affected by the breakpoint we set, the Service will continue to be executed only after the test is completed. Finally, the remote debugging function is really powerful. Make full use of remote debugging to stay away from bugs!
---- ☆☆☆-- Return-> the simplest IntelliJ IDEA tutorial in history <-directory -- ☆☆☆ ----
-
Top
-
2
-
Step on
-
1
View comments