vlambda博客
学习文章列表

tomcat8源码分析00-源码启动

 
   
   
 
  1. git clone https://github.com/apache/tomcat.git tomcat8

  2. # 克隆源码并切换到8.5.x版本

  3. git checkout 8.5.x

2.项目根目录新建并配置pom.xml

 
   
   
 
  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. <modelVersion>4.0.0</modelVersion>

  6. <groupId>cn.xxx</groupId>

  7. <artifactId>Tomcat8.5.x</artifactId>

  8. <name>Tomcat8</name>

  9. <version>8.5.x</version>

  10. <build>

  11. <finalName>Tomcat8</finalName>

  12. <sourceDirectory>java</sourceDirectory>

  13. <resources>

  14. <resource>

  15. <directory>java</directory>

  16. </resource>

  17. </resources>

  18. <plugins>

  19. <plugin>

  20. <groupId>org.apache.maven.plugins</groupId>

  21. <artifactId>maven-compiler-plugin</artifactId>

  22. <version>2.3</version>

  23. <configuration>

  24. <encoding>UTF-8</encoding>

  25. <source>1.8</source>

  26. <target>1.8</target>

  27. </configuration>

  28. </plugin>

  29. </plugins>

  30. </build>

  31. <dependencies>

  32. <dependency>

  33. <groupId>org.apache.ant</groupId>

  34. <artifactId>ant</artifactId>

  35. <version>1.10.1</version>

  36. </dependency>

  37. <dependency>

  38. <groupId>org.apache.ant</groupId>

  39. <artifactId>ant-apache-log4j</artifactId>

  40. <version>1.9.5</version>

  41. </dependency>

  42. <dependency>

  43. <groupId>org.apache.ant</groupId>

  44. <artifactId>ant-commons-logging</artifactId>

  45. <version>1.9.5</version>

  46. </dependency>

  47. <dependency>

  48. <groupId>javax.xml.rpc</groupId>

  49. <artifactId>javax.xml.rpc-api</artifactId>

  50. <version>1.1</version>

  51. </dependency>

  52. <dependency>

  53. <groupId>wsdl4j</groupId>

  54. <artifactId>wsdl4j</artifactId>

  55. <version>1.6.2</version>

  56. </dependency>

  57. <dependency>

  58. <groupId>org.eclipse.jdt.core.compiler</groupId>

  59. <artifactId>ecj</artifactId>

  60. <version>4.6.1</version>

  61. </dependency>

  62. <dependency>

  63. <groupId>junit</groupId>

  64. <artifactId>junit</artifactId>

  65. <version>4.12</version>

  66. <scope>test</scope>

  67. </dependency>

  68. <dependency>

  69. <groupId>org.easymock</groupId>

  70. <artifactId>easymock</artifactId>

  71. <version>3.5.1</version>

  72. <scope>test</scope>

  73. </dependency>

  74. <dependency>

  75. <groupId>biz.aQute.bnd</groupId>

  76. <artifactId>biz.aQute.bndlib</artifactId>

  77. <version>5.2.0</version>

  78. <scope>provided</scope>

  79. </dependency>

  80. </dependencies>

  81. </project>

如果idea没有识别到maven项目需要自己手动link一下。右键pom.xml找到Add as Maven Project

点击maven的clean可能提示找不到jdk,按着提示配置jdk

tomcat8源码分析00-源码启动
tomcat8源码分析00-源码启动

3.idea设置启动配置

 
   
   
 
  1. Main class:

  2. org.apache.catalina.startup.Bootstrap

  3. VM options:

  4. -Dcatalina.home=/Users/username/Desktop/java/tomcat8 -Dcatalina.base=/Users/username/Desktop/java/tomcat8 -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/Users/username/Desktop/java/tomcat8/conf/logging.properties -Dfile.encoding=UTF8 -Duser.language=en -Duser.region=US

4.启动后无法编译jsp文件报错500 找到ContextConfig类,找到代码webConfig();在下一行增加

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