Tomcat02-- up and running Tomcat source code

1. Preparations

1. Download tomcat source package

2. Create an empty project

2. Procedure

2.1 will download the source code extract to the project

Figure:

2.2 Construction of the project

2.2.1 Create a home folder

Into the extracted directory, create a directory called home, and then conf and webapps directory to your home directory, as shown:

2.2.2 Creating pom.xml

Create a pom.xml file in the unzipped directory, and the introduction of tomcat dependencies, as shown:

pom.xml

<?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.tomcat</groupId>
    <artifactId>apache-tomcat-8.5.50-src</artifactId>
    <name>Tomcat8.5</name>
    <version>8.5</version>
 
    <build>
        <finalName>Tomcat8.5</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>2.3</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>
        </dependency>
        <dependency>
            <groupId>ant</groupId>
            <artifactId>ant</artifactId>
            <version>1.7.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.5.1</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.soap</groupId>
            <artifactId>javax.xml.soap-api</artifactId>
            <version>1.4.0</version>
        </dependency>

    </dependencies>
</project>

3. Import Project

file——new——Module from existing sources,如图:

Select import, select maven, as shown:

Click finish, and then select the file, as shown:

Note: If the IDE is not configured maven, configure maven

4. Start the configuration information idea

In java directory to find the Bootstrap class, as shown:

It can be seen under a main method, as shown:

So, we need to configure the class.

4.1 Procedure

4.1.1 Open Configuration

1. Click Add Configuration, as shown:

2. Click on the arrow, as shown:

3. Select Application, click the plus sign, as shown:

4. Click Application, get configuration interface, as shown:

4.1.2 Configuring mainClass

     Configuration main class, ellipses right click, select startup class as:

4.1.3 JVM configuration parameters (VM options)

-Dcatalina.home=D:/ideaWorkspace/tomcat/apache-tomcat-8.5.50-src/home
-Dcatalina.base=D:/ideaWorkspace/tomcat/apache-tomcat-8.5.50-src/home
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.util.logging.config.file=D:/ideaWorkspace/tomcat/apache-tomcat-8.5.50-src/home/conf/logging.properties

Click apply, click on OK, the configuration is complete.

5. Start Tomcat project

Run directly, as shown:

When compiled, reported the following error when, as shown: 

Back up and delete the file, running a successful start

Then enter the URL in your browser: HTTP: // localhost: 8080 / , reported a 500 error, as shown:

产生错误的原因是,我们直接启动mainClass的时候,没有加载JasperInitializer,从而无法编译JSP。解决办法是在tomcat的源码ContextConfig中的ConfigureStart函数中手动将JSP解释器初始化。 

在  org.apache.catalina.startup下的ContextConfig类中的configureStart方法的webConfig();下面,加上如下一段代码

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

然后重启,在访问,发现可以了

 

发布了128 篇原创文章 · 获赞 6 · 访问量 3224

Guess you like

Origin blog.csdn.net/weixin_43318134/article/details/103899804