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

How to debug Tomcat source code

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

Share

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

How to debug the Tomcat source code, in view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.

Today, take the Tomcat source code as an example to summarize the way of source code debugging.

For example, the process of dealing with a problem is roughly finding, analyzing and solving problems. Let's briefly summarize the debugging of the source code:

Get the source code

There are many ways to download the source code of Tomcat.

Download from github (https://github.com/apache/tomcat)

Download from Tomcat's SVN server (http://svn.apache.org/repos/asf/tomcat/)

Download from Tomcat's official website (http://tomcat.apache.org/download-80.cgi)

At the bottom of the download page of each version, there will be a corresponding source code package for download, as shown below.

Import the source code into IDE

There should be no problem with every Developer for this job, we don't write too much about it.

Add dependency

After importing into IDE, many files will prompt for a red X, indicating that a dependent jar file is missing. At this point, you can add the relevant files already in the system, and if you organize the project in the form of this Maven, you can directly add the corresponding dependencies.

Run the application

In this step, you need to find the entry to the application, that is, Main-Class, and then execute the class. Of course, for some applications that require the necessary input parameters at run time, Tomcat needs to specify catalina.home.

Such entry applications can be found in the following ways:

If the application is provided as a jar file, there will be a

MANIFEST.MF file.

If it is not specified in the jar file, or if the application is launched as a script, you can find the default execution class in the script, such as Tomcat's startup script catalina.bat:

Set MAINCLASS=org.apache.catalina.startup.Bootstrap

After determining the main class in the above way, configure the corresponding VM parameters and apply your own parameters as needed, and the code runs. Then, according to what you want to know, set a breakpoint and start the Debug journey.

The above are general steps. When it comes to Tomcat, let's talk about specific ways and means.

Debugging in the form of engineering

Take Eclipse as an example

First create a project Java project.

Import the source code file, which can be done as follows:

Copy it all in.

Introduced in the form of link source. (right-click the project and select Link source in build Path)

Add the jar file under the lib of the installed Tomcat to the project dependency, and then add other required jar files, such as ant.jar

Set up the main class

Set parameters

Click Debug, the program is running, start debugging it.

Debugging in Attach mode

Create a new project and import the source code. At this point, you can start Tomcat as debug. In order to Attach the code into the process at the first time, you need to set the jpda to automatically pause after startup and wait for the application connection.

Can be set directly in the script file catalina.bat

Set JPDA_OPTS=-agentlib:jdwp=transport=%JPDA_TRANSPORT%,address=%JPDA_ADDRESS%,server=y,suspend=%JPDA_SUSPEND%

Just change the red content above to y, or you can set it on the command line first.

Then execute the command.

Catalina.bat jpda start

The default connection port is 8000

After that, the project can be debugged directly by remote debugging.

At this point, you can debug the source code of Tomcat. If you want to track the process at startup, you can first add breakpoints in Bootstrap and start debugging.

The answer to the question about how to debug the Tomcat source code is shared here. I hope the above content can be of some help to everyone. If you still have a lot of doubts to solve, you can follow the industry information channel to learn more about it.

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

Internet Technology

Wechat

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

12
Report