Tomcat source code to run (a)

1, source code download: http://archive.apache.org/dist/tomcat/tomcat-9/v9.0.33/src/

2. Create an empty project: apache-tomcat

3, into the project folder apache-tomcat extract the source package apache-tomcat-9.0.33-src.zip get apache-tomcat-9.0.33-src folder

4, into the apache-tomcat-9.0.33-src folder, and create a directory named home, and conf, webapps directory into the home directory

5. Create a pom.xml file in the apache-tomcat-9.0.33-src folder, as follows:

 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>apache‐tomcat‐9.0.33‐src</artifactId>
 9     <name>Tomcat9.0</name>
10     <version>9.0</version>
11 
12     <build>
13         <finalName>Tomcat9.0</finalName>
14         <sourceDirectory>java</sourceDirectory>
15        <!-- <testSourceDirectory>test</testSourceDirectory>-->
16         <resources>
17             <resource>
18                 <directory>java</directory>
19             </resource>
20         </resources>
21 
22        <!-- <testResources>
23             <testResource>
24                 <directory>test</directory>
25             </testResource>
26         </testResources>-->
27         <plugins>
28             <plugin>
29                 <groupId>org.apache.maven.plugins</groupId>
30                 <artifactId>maven-compiler-plugin</artifactId>
31                 <version>3.5.1</version>
32                 <configuration>
33                     <encoding>UTF‐8</encoding>
34                     <source>1.8</source>
35                     <target>1.8</target>
36                 </configuration>
37             </plugin>
38         </plugins>
39     </build>
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     </dependencies>
73 </project>
View Code

Create a directory Click apache-tomcat-9.0.33-src pom.xml file in the directory of the project 6. Before entering the IDEA find import, import

7. Locate startup class Bootstrap, at java / org / apache / catalina / startup

8. Start configuration Edit Configurations category class and is configured to start the parameter setting VM
   1. Select the Application +
   2. Start the class name provided
   3. Main class selection has been selected to Bootstrap class
   4. VM options set (changed to the following 3,4 you position the native project files)

    -Dcatalina.home=F:/IDEA_WorkSpace/itcast_tomcat/apache-tomcat-9.0.33-src/home
    -Dcatalina.base=F:/IDEA_WorkSpace/itcast_tomcat/apache-tomcat-9.0.33-src/home
    -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
    -Djava.util.logging.config.file=F:/IDEA_WorkSpace/itcast_tomcat/apache-tomcat-9.0.33-src/home/conf/logging.properties

 

 

10, compile the project, it may be error
    Error: (320, 45) java : can not find symbol
    symbol: variable VERSION_9, 10,11,12
    location: class org.eclipse.jdt.internal.compiler.impl.CompilerOptions
    unified error VERSION_1_8 can be changed (or changed version of the JDK your project)
11, run the project
  up and running successfully;
12, why there will be garbled console:
  reasons : generally Chinese encoding mismatch causes; by tracking, read ResourceBundle is found take org \ apache \ catalina \ useless when startup \ LocalStrings_zh_CN.properties utf8 file decoding leads;
  solution : modify org.apache.tomcat.util.res.StringManager class getString function;
  by the
  IF (= the bundle null!) {
  STR bundle.getString = (Key);
  }
  to
  IF (= the bundle null!) {
  STR = new new String (bundle.getString (Key) .getBytes ( "the ISO-8859-1"), "UTF-. 8");
  }
  run again, the console without distortion.

13. Access page, but reported 500 errors  

  The reason : we started directly org.apache.catalina.startup.Bootstrap when there is no load JasperInitializer, so as not compile JSP.

  The solution is in the tomcat source ContextConfig configureStart function of manually initializing JSP parser.

 

  Solve : find ContextConfig this class at java / org / apache / catalina / startup

  In webConfig configureStart () method (); (775 lines of code) plus the following

  

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

 

14. visit again, success

 

Guess you like

Origin www.cnblogs.com/zhaomo/p/12535872.html