Java使用maven编译tomcat

1.下载tomcat源码

git clone https://github.com/apache/tomcat.git
git branch 9.0.43

2.新建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>tomcat</artifactId>
    <name>tomcat</name>
    <version>9.0.43</version>

    <dependencies>
        <dependency>
            <groupId>biz.aQute.bnd</groupId>
            <artifactId>biz.aQute.bndlib</artifactId>
            <version>5.2.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant</artifactId>
            <version>1.10.5</version>
        </dependency>
        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
            <version>1.6.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.geronimo.specs</groupId>
            <artifactId>geronimo-jaxrpc_1.1_spec</artifactId>
            <version>2.1</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jdt</groupId>
            <artifactId>ecj</artifactId>
            <version>3.26.0</version>
        </dependency>
        <dependency>
            <groupId>org.easymock</groupId>
            <artifactId>easymock</artifactId>
            <version>4.0.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

3.使用idea打开项目

4.指定项目的源码和资源目录

File菜单->选择Project Structure->选择Modules->选择java->点击Sources->选择res->点击Resources->点击确定

image

5.启动Tomcat

找到类org.apache.catalina.startup.Bootstrap

  • 报错修复

①启动Tomcat出现java.lang.ClassNotFoundException: listeners.ContextListener

删除webapps目录下的sample文件夹

②启动tomcat出现`org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.index_jsp
java.lang.ClassNotFoundException: org.apache.jsp.index_jsp`异常

找到org.apache.catalina.startup.ContextConfig,搜索webconfig();,在该语句的下面添加context.addServletContainerInitializer(new JasperInitializer(), null);代码

如果觉得我的文章对你有用,请随意赞赏