Describes how IntelliJ IDEA can remotely debug Tomcat, intellijtomcat

Source: Internet
Author: User

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 ConfigurationsTo go to the following page:

As shown in, we enterRun/Debug ConfigurationsInterface, and then click+, SelectRemote:

  • Note 1: Run the command line parameters of the remote JVM;
  • Note 2: Transmission mode. The default value isSocket;
  • Mark 3: Debugging mode. The default value isAttach;
  • Note 4: Server IP address. The default value islocalhostTo change the IP address of the target server;
  • Mark 5: Server port number. The default value is5005, 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 isSocket;
    • 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 isAttach;
    • 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 issetThe Linux import value must be enclosed in single quotes.''While Windows does not.

Next, modifycatalina.shFile (if it is a Windows system, modifycatalina.batFile), 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, EnterDebugMode. 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, startDebugMode, and then execute the program at the beginning of the Service to enter the breakpoint we set. In addition, if we configureRemoteAnd associate it with a Tomcat.DebugAll 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 configureRemoteAnd 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.DebugAfter 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.