Tomcat源码解析(1)-项目构建

原创
2020/07/13 20:29
阅读数 35

1.Tomcat官网源码下载 ;

2.在Tomcat根目录下添加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>cn.linxdcn</groupId>
    <artifactId>Tomcat9.0</artifactId>
    <name>Tomcat9</name>
    <version>9.0</version>
 
    <build>
        <finalName>Tomcat9</finalName>
        <sourceDirectory>java</sourceDirectory>
        <resources>
            <resource>
                <directory>java</directory>
            </resource>
        </resources>
        <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>org.apache.ant</groupId>
            <artifactId>ant</artifactId>
            <version>1.9.5</version>
        </dependency>
        <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant-apache-log4j</artifactId>
            <version>1.9.5</version>
        </dependency>
        <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant-commons-logging</artifactId>
            <version>1.9.5</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.rpc</groupId>
            <artifactId>javax.xml.rpc-api</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
            <version>1.6.2</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jdt.core.compiler</groupId>
            <artifactId>ecj</artifactId>
            <version>4.4</version>
        </dependency>
    </dependencies>
</project>


3.新建source目录,将conf、webapps目录移动到source目录;

4.将项目导入IDEA,添加以下配置

5.没有Main class,搜索Bootstrap添加VM options位置添加参数,设置home、base目录为刚才新建的source目录

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

 6.此时启动Bootstrap类,访问8080端口,页面访问失败, 提示加载jsp的Jasper类没有初始化;

7.修改ContextConfig类,在configureStart()方法添加context.addServletContainerInitializer(new JasperInitializer(),null);

8.再次访问8080端口,正常显示Tomcat首页。

展开阅读全文
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部