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 find main function in tomcat

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

How to find the main function in tomcat, I believe many inexperienced people don't know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Every student who does java web will hear the name of tomcat from the first day of his career. Until now, after working for several years, he is still inseparable from tomcat every day, but the form of use has changed. I remember that when I first used tomcat, I had to change a port number inside server.xml. Now there is no shadow of tomcat in the code, but it is undeniable that our web program is still run with tomcat.

I remember an interview when the interviewer asked, "does tomcat have a main function?" At that time, I thought that running tomcat is the directory where tomcat is configured, and then click to run it. There is no need to write a java program, and there is a main function that right-click to run / debug and so on. The following figure shows the configuration of tomcat in idea. Then I answered that there was no main function, and then I went home and waited for notice.

Start tomcat

By going home and so on, we can infer that tomcat has a main function, so where is the main function? Let's start by starting tomcat (the following analysis is based on 9.0.12). When starting, look for the startup.bat/startup.sh under the bin directory, circle the key point! The following three circles are the key points

Click on startup.sh first. It feels like he didn't do anything, but just executed catalina.sh.

Then let's walk into the catalina.sh and have a look at it. How can we start with more than 600 lines of script? of course, this article is not going to talk about this from the beginning. Today we are just looking for the main function, then we are going to look for the java command here.

In this script, we will see a large number of such scripts:

# For Cygwin, switch paths to Windows format before running java

If $cygwin; then

JAVA_HOME= `cygpath-- absolute-- windows "$JAVA_HOME" `

JRE_HOME= `cygpath-- absolute-- windows "$JRE_HOME" `

CATALINA_HOME= `cygpath-- absolute-- windows "$CATALINA_HOME" `

CATALINA_BASE= `cygpath-- absolute-- windows "$CATALINA_BASE" `

CATALINA_TMPDIR= `cygpath-- absolute-- windows "$CATALINA_TMPDIR" `

CLASSPATH= `cygpath-- path-- windows "$CLASSPATH" `

JAVA_ENDORSED_DIRS= `cygpath-- path-- windows "$JAVA_ENDORSED_DIRS" `

Fi

If [- z "$JSSE_OPTS"]; then

JSSE_OPTS= "- Djdk.tls.ephemeralDHKeySize=2048"

Fi

JAVA_OPTS= "$JAVA_OPTS $JSSE_OPTS"

It is not difficult to guess from the if then keyword, which is to splice different parameters for the operation of tomcat according to the situation of the system. Let's skip the code and move on, as shown in the following figure, corresponding to the last start command of startup.sh, and then start the familiar java program startup command: nohup java-jar xxxxx.jar > log.log &.

As you can see at line 460, the org.apache.catalina.startup.Bootstrap class is started. If nothing happens, there should be the Main function we are looking for. We found this class in idea. That's right! The Main function is in here!

After reading the above, have you mastered how to find the main function in tomcat? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

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