Tomcat源码Idea maven启动

一、下载tomcat源码

https://github.com/apache/tomcat/tree/8.5.x

二、建立pom

 1 xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0"
 3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 5 
 6     <modelVersion>4.0.0modelVersion>
 7     <groupId>org.apache.tomcatgroupId>
 8     <artifactId>Tomcat8.5artifactId>
 9     <name>Tomcat8.0name>
10     <version>8.0version>
11 
12     <build>
13         <finalName>Tomcat8.5finalName>
14         <sourceDirectory>javasourceDirectory>
15         <testSourceDirectory>testtestSourceDirectory>
16         <resources>
17             <resource>
18                 <directory>javadirectory>
19             resource>
20         resources>
21         <testResources>
22             <testResource>
23                 <directory>testdirectory>
24             testResource>
25         testResources>
26         <plugins>
27             <plugin>
28                 <groupId>org.apache.maven.pluginsgroupId>
29                 <artifactId>maven-compiler-pluginartifactId>
30                 <version>2.3version>
31                 <configuration>
32                     <encoding>UTF-8encoding>
33                     <source>1.8source>
34                     <target>1.8target>
35                 configuration>
36             plugin>
37         plugins>
38     build>
39 
40     <dependencies>
41         <dependency>
42             <groupId>junitgroupId>
43             <artifactId>junitartifactId>
44             <version>4.12version>
45             <scope>testscope>
46         dependency>
47         <dependency>
48             <groupId>org.easymockgroupId>
49             <artifactId>easymockartifactId>
50             <version>3.4version>
51         dependency>
52         <dependency>
53             <groupId>antgroupId>
54             <artifactId>antartifactId>
55             <version>1.7.0version>
56         dependency>
57         <dependency>
58             <groupId>wsdl4jgroupId>
59             <artifactId>wsdl4jartifactId>
60             <version>1.6.2version>
61         dependency>
62         <dependency>
63             <groupId>javax.xmlgroupId>
64             <artifactId>jaxrpcartifactId>
65             <version>1.1version>
66         dependency>
67         <dependency>
68             <groupId>org.eclipse.jdt.core.compilergroupId>
69             <artifactId>ecjartifactId>
70             <version>4.5.1version>
71         dependency>
72 
73     dependencies>
74 project>
View Code

编译可能有个测试类过不了。删除即可。

Tomcat源码Idea maven启动_第1张图片

三、新建catalina-home目录

  • 把webapp文件夹和conf文件夹copy到Catalina-home目录
  • 新建空文件夹temp、log、lib

Tomcat源码Idea maven启动_第2张图片

四,设置启动参数

-Dcatalina.home=catalina-home -Dcatalina.base=catalina-home -Djava.endorsed.dirs=catalina-home/endorsed -Djava.io.tmpdir=catalina-home/temp -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=catalina-home/conf/logging.properties

Tomcat源码Idea maven启动_第3张图片

 

  

  • main class设置为 org.apache.catalina.startup.Bootstrap
  • vm option复制上面的参数主要是设置Catalina的启动目录

 五、启动

Tomcat源码Idea maven启动_第4张图片

 至此,tomcat已经成功启动。

六、访问tomcat

 

Tomcat源码Idea maven启动_第5张图片

 

发现有NPE

解决:在Bootstrap中启动jasper,修改代码,在ContextConfig中加入如下代码

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

Tomcat源码Idea maven启动_第6张图片

启动成功。

Tomcat源码Idea maven启动_第7张图片

 

你可能感兴趣的:(Tomcat源码Idea maven启动)