Source environment construction-Tomcat 8 source code imported into IDEA (Maven)

Build and import IDEA based on Mavan

1. The Tomcat source code address is  http://tomcat.apache.org/download-80.cgi . The Tomcat version used in this article is apache-tomcat-8.5.41-src.

Note: The installation directory of this article is E:\apache-tomcat-8.5.41-src, which will be used many times and needs to be replaced with your own.

Technical picture

 

2. Create a new pom.xml file in the root directory of apache-tomcat-8.5.41-src and import the dependent jar package. The content of the file is as follows

Technical picture

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>org.apache</groupId>
    <artifactId>tomcat</artifactId>
    <name>apache-tomcat-8.5.24</name>
    <version>8.5.24</version>

    <build>
        <finalName>Tomcat-8.5.24</finalName>
        <sourceDirectory>java</sourceDirectory>
        <testSourceDirectory>test</testSourceDirectory>
        <resources>
            <resource>
                <directory>java</directory>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>test</directory>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.easymock</groupId>
            <artifactId>easymock</artifactId>
            <version>3.4</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant</artifactId>
            <version>1.10.0</version>
        </dependency>
        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
            <version>1.6.2</version>
        </dependency>
        <dependency>
            <groupId>javax.xml</groupId>
            <artifactId>jaxrpc</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jdt.core.compiler</groupId>
            <artifactId>ecj</artifactId>
            <version>4.6.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.glassfish/javax.xml.rpc -->
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.xml.rpc</artifactId>
            <version>3.0.1-b03</version>
        </dependency>

    </dependencies>
</project>

 

3. Delete test/util/TestCookieFilter.java, otherwise an error will be reported during startup.

 

4. Select in IDEAFile -> New -> Project from Existing Sources...,按照Maven项目新建即可。

5. Choose Run -> Edit Configurations.

Main class:
   org.apache.catalina.startup.Bootstrap
VM options:
    -Dcatalina.home=E:\apache-tomcat-8.5.41-src -Dcatalina.base=E:\apache-tomcat-8.5.41-src -Djava.endorsed.dirs=E:\apache-tomcat-8.5.41-src/endorsed -Djava.io.tmpdir=E:\apache-tomcat-8.5.41-src/temp -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=E:\apache-tomcat-8.5.41-src/conf/logging.properties

Technical picture

 

6. Add jsp initialization program, add in org.apache.catalina.startup.ContextConfig.java class

context.addServletContainerInitializer(new JasperInitializer(), null);

Technical picture

 

7. Just start the visit, the main method of org.apache.catalina.startup.Bootstrap.java is the start entry

8. Add the web project to Tomcat to see the running process. The configuration project is the same as the configuration project in server.xml. In the E: \ \ apache-tomcat- 8.5.41-src conf under  server.xml  in the  Host add nodes

<Context docBase="E:/apache-tomcat-8.5.41-src/webapps/ROOT" path="/mytomcat" debug="0"  reloadable="true"/>

9. Start the project and visit http://localhost:8080/

Technical picture

 

problem solved

If the following error is reported when starting: Error:osgi: [apache-tomcat-8.5.41-src] Invalid value for Bundle-Version, @VERSION@ does not match [0-9]{1,9}(.[0 -9]{1,9}(.[0-9]{1,9}(.[0-9A-Za-z_-]+)?)?)?

Just change @version@ to 1.1 to use

Look for the entry class: here is the startup bat of windows as an example, the sh of linux is similar

 

 

 

In order to better use Tomcat, it is necessary to optimize it. Optimization has certain optimization indicators, and these indicators need to be monitored to facilitate the search for optimization problems

The industry also has good monitoring tools:

 Tomcat management and monitoring tool psi probe

Download the war package of Psi Probe from GitHub

https://github.com/psi-probe/psi-probe/releases

Second, department

1. Copy the downloaded war package to the webapps/ directory of tomcat

2. Configure the conf/tomcat-users.xml file.

<!-- psi probe related role configuration-->

<role rolename="probeuser"/>
<role rolename="poweruser"/>
<role rolename="poweruserplus"/>
<role rolename="manager-gui"/>

<user username="admin" password="123456" roles="manager-gui"/>

 

Among them, admin/123456 is the username and password required to access the probe interface

3. Configure the bin/catalina.sh or bin/catalina.bat file to enable remote jvm support ( if not needed, skip this step )

(1) Tomcat (catalina.sh) under Linux:

# Turn on remote jvm support

export JAVA_OPTS=$JAVA_OPTS" -Dcom.sun.management.jmxremote"

(2) Tomcat (catalina.bat) under Windows:

rem enable remote jvm support

set JAVA_OPTS=-Dcom.sun.management.jmxremote

 

After modification, it is recommended to restart Tomcat once

Three, use Psi Probe

In the browser, access the monitoring platform through http://ip:port/probe, enter the user name and password configured in the tomcat-users.xml file

The following error will occur at this time:

 

Check the problem below:

1. Find logs

Find key exception information, guess and verify:

 

 

 

 

Main function introduction

(1) List of applications 

This page displays all the applications deployed in this Tomcat instance, and lists basic information:

  • Requests: The total number of requests processed by this app since it was launched
  • Sessions: The number of sessions currently active for this application (click to display a list of sessions)
  • Session attributes: the number of current session attributes of this application
  • Number of attributes: the number of attributes of the current ServletContext level of this application (click to see the specific attribute list)
  • Timeout: the timeout period of the session
  • JDBC usage: only useful when Tomcat's own JDBC connection pool is used

(2) Application details

Click on an application in the application list to enter the application details interface

There are 10 sub-interfaces in the application details interface:

  • Summary: Display summary information of the application, and start and stop the application
  • Session: List all current active sessions of this application, you can see the detailed information of each session, and the attributes saved in the session, and you can also force the destruction of the session
  • Attribute: List the attribute list of ServletContext level
  • JSPs: List all JSP pages under this application, and you can manually compile JSP pages
  • Resource: only works when a tomcat resource (such as a JDBC connection pool) is defined, and displays related information about the resource
  • Context description file: display the context.xml of this application
  • Release description file: show the web.xml of this application
  • Servlets: Show all Servlets under this application, and performance statistics of each Servlet
  • Filter: Show all Filters under this application
  • Parameters: Display the initial Context parameters of this application

(3) Data source

When using the JDBC connection pool that comes with Tomcat, this interface can display the detailed information and status data of the JDBC connection pool, such as the maximum number of active connections, the minimum number of idle connections, the number of current active connections, etc.

(4) Release

In this interface, you can publish applications to Tomcat

(5) Log

Show the log files generated by this Tomcat instance, which can be browsed and downloaded online

(6) Thread

Display all thread information in the Tomcat process, click on the thread execution point to see the stacktrace of the thread

The status column indicates:

  • RUNNABLE: The system is running;
  • WAITING: This state refers to a thread that owns a lock, calls the wait method, and waits for other thread owners to call notify to wake up the thread to continue the next operation;
  • TIME_WAITING: Restricted waiting, which usually occurs when calling wait, join, etc., and after the thread sleeps, it will also enter the time_waiting state;
  • BLOCKED: Blocked state, which means that the thread is busy and is executing, and there may be resource waiting. We need to pay attention to the blocked state thread for a long time, and dump the thread stack to find the program, so as to analyze what to do and wait for those resources;
  • TERMINATED: Indicates that the run method has been executed and entered a dead state. If the thread holds for a long time, it may not be recycled.

(7) Thread pool

Click on the thread pool in the thread interface to enter

(8) System information

This interface can display JVM and operating system information, such as JVM memory usage, JVM parameters, CPU/memory/Swap usage, etc.

(9) Connector

The Tomcat Connector information is displayed in this interface, including historical statistics of each connector processing request, and the request information currently being processed by the Connector

 

The above source code import and monitoring optimization tools are all configured, and then you can perform source code analysis and performance optimization operations

 

everything's ready! Start your path to source code!

 

Guess you like

Origin blog.csdn.net/Coder_Boy_/article/details/110210635