Tomcat源码环境idea配置

下载

https://tomcat.apache.org/download-80.cgi 下载源码,解压。

配置环境

新建一个目录,把解压好的文件目录复制进去,新建一个文件,主要把源代码里面的conf复制,其他随意,结果是这个样子:(也可以不用分离,分离开好管理)

20200404225435

在外层目录新建pom文件,让源代码目录成为idea的模块。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?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>com.huf</groupId>
<artifactId>apache-tomcat</artifactId>
<name>apache-tomcat-source</name>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
<module>apache-tomcat-8.5.53-src</module>
</modules>
</project>

在源码中新建pom文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?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>Tomcat8.5.53</artifactId>
<name>Tomcat8.5.53</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.0.2</version>

<configuration>
<encoding>UTF-8</encoding>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.5</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</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.6.1</version>
</dependency>
</dependencies>
</project>

构建

在idea中打开,自动状态maven项目。

20200404232607

catalina目录是运行环境,构建完成后配置运行环境。

新建配置

20200404230428

配置如下:

20200404232546

1
2
3
4
5
6
7
-Dcatalina.home=catalina
-Dcatalina.base=catalina
-Djava.endorsed.dirs=catalina/endorsed
-Djava.io.tmpdir=catalina/temp
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.util.logging.config.file=catalina/conf/logging.properties
-Dfile.encoding=UTF-8

启动,开始构建,构建过程如果test报错,把pom中的test移除。

启动成功后,浏览,报错HTTP Status 500 – Internal Server Error

这是因为8以后版本,JSP引擎没有初始化进去,手动增加代码初始化:

org/apache/catalina/startup/ContextConfig.java

1
2
3
webConfig();
//添加初始化JasperInitializer
context.addServletContainerInitializer(new JasperInitializer(), null);

20200404232406
重启后,即可。
20200404232341