tomcat9源码编译
2020-02-27 本文已影响0人
loveFXX
编译前准备
1、jdk和maven环境
2、下载tomcat安装包
https://tomcat.apache.org/download-90.cgi
3、解压到你的文件夹
我的解压目录是(D:\workspase\tomcat\apache-tomcat-9.0.31-src)
pom.png
4、创建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.mytomcat</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>
<configuration>
<source>1.8</source>
<target>1.8</target>
<optimize>true</optimize>
<debug>true</debug>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
</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>
导入到IDEA
1、导入源文件
File--Open 导入你解压的文件夹(D:\workspase\tomcat\apache-tomcat-9.0.31-src)
tomcat.png
2、设置JDK环境并下载依赖
structure.png
3、创建启动项
Add Configuration->
Configuration.png
3.1、参数添加
Main class:org.apache.catalina.startup.Bootstrap
VM options:-Dcatalina.home="D:/workspase/tomcat/apache-tomcat-9.0.31-src"
catalina.png
4、compile Tomcat
jdbc-pool的pom文件依赖添加并下载
jdbc.png
compile.png
5、错误代码注释掉(JDTCompiler类),重新编译
JDTCompiler1.png
JDTCompiler2.png
如果还有其他类(JmxRemoteLifecycleListener)报错只要注释掉就可以,然后重新编译
6、编译成功
build.png
访问欢迎页测试
1、直接运行测试
image.png
2、乱码处理
VM options添加: -Duser.language=en
language.png
3、重新运行访问localhost:8080会报jsp错误
jsp.png
4、创建resouces文件夹
在这个文件夹下创建META-INT文件夹,然后把.\res\META-INF\jasper.jar文件下的services文件夹,复制到.\resouces\META-INT目录下
service.png
META-INT.png
5、设置resouces目录是Resources Root目录
image.png
6、访问localhost:8080
welcome.png