一、下載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/PO ...
一、下載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.0</modelVersion> 7 <groupId>org.apache.tomcat</groupId> 8 <artifactId>Tomcat8.5</artifactId> 9 <name>Tomcat8.0</name> 10 <version>8.0</version> 11 12 <build> 13 <finalName>Tomcat8.5</finalName> 14 <sourceDirectory>java</sourceDirectory> 15 <testSourceDirectory>test</testSourceDirectory> 16 <resources> 17 <resource> 18 <directory>java</directory> 19 </resource> 20 </resources> 21 <testResources> 22 <testResource> 23 <directory>test</directory> 24 </testResource> 25 </testResources> 26 <plugins> 27 <plugin> 28 <groupId>org.apache.maven.plugins</groupId> 29 <artifactId>maven-compiler-plugin</artifactId> 30 <version>2.3</version> 31 <configuration> 32 <encoding>UTF-8</encoding> 33 <source>1.8</source> 34 <target>1.8</target> 35 </configuration> 36 </plugin> 37 </plugins> 38 </build> 39 40 <dependencies> 41 <dependency> 42 <groupId>junit</groupId> 43 <artifactId>junit</artifactId> 44 <version>4.12</version> 45 <scope>test</scope> 46 </dependency> 47 <dependency> 48 <groupId>org.easymock</groupId> 49 <artifactId>easymock</artifactId> 50 <version>3.4</version> 51 </dependency> 52 <dependency> 53 <groupId>ant</groupId> 54 <artifactId>ant</artifactId> 55 <version>1.7.0</version> 56 </dependency> 57 <dependency> 58 <groupId>wsdl4j</groupId> 59 <artifactId>wsdl4j</artifactId> 60 <version>1.6.2</version> 61 </dependency> 62 <dependency> 63 <groupId>javax.xml</groupId> 64 <artifactId>jaxrpc</artifactId> 65 <version>1.1</version> 66 </dependency> 67 <dependency> 68 <groupId>org.eclipse.jdt.core.compiler</groupId> 69 <artifactId>ecj</artifactId> 70 <version>4.5.1</version> 71 </dependency> 72 73 </dependencies> 74 </project>View Code
編譯可能有個測試類過不了。刪除即可。
三、新建catalina-home目錄
- 把webapp文件夾和conf文件夾copy到Catalina-home目錄
- 新建空文件夾temp、log、lib
四,設置啟動參數
-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
- main class設置為 org.apache.catalina.startup.Bootstrap
- vm option複製上面的參數主要是設置Catalina的啟動目錄
五、啟動
至此,tomcat已經成功啟動。
六、訪問tomcat
發現有NPE
解決:在Bootstrap中啟動jasper,修改代碼,在ContextConfig中加入如下代碼
context.addServletContainerInitializer(new JasperInitializer(), null);
啟動成功。