Tomcat9 Source code Analysis source download, compile and debug

Source: Internet
Author: User
Tags xmlns tomcat
First, the environment

Here are the environments I compiled Tomcat for OS X Yosemite version 10.10.5 Intellij idea 2017.1 Java version 1.8.0_65 Apache Maven 3.3.9 Tomcat 9.0. 0.m21

(1) JDK1.8

Tomcat9 need at least jdk1.8 version, there are many Java installation tutorials on the web.

(2) Tomcat source

Access Tomcat download address, the bottom of the tar package or ZIP package source code

(3) maven3.0+

Tomcat is compiled by default with ant, and if you want to compile tomcat in the official way, you can access the website how to build Tomcat. I have been using MAVEN as a management tool, so I found some information on the Internet, I compiled the method of using MAVEN to compile Tomcat. ii. Preparation of pom.xml files

Unzip the Tomcat source to/yourpath/tomcat9, as shown below



In the/yourpath/tomcat9 directory, add the Pom.xml file with the following content

<?xml version= "1.0" encoding= "UTF-8"?> <project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "htt P://www.w3.org/2001/xmlschema-instance "xsi:schemalocation=" http://maven.apache.org/POM/4.0.0 Http://maven.apach E.org/xsd/maven-4.0.0.xsd "> <modelVersion>4.0.0</modelVersion> <groupid>cn.linxdcn</grou pid> <artifactId>Tomcat9.0</artifactId> <name>Tomcat9</name> <version>9.0< /version> <build> <finalName>Tomcat9</finalName> <sourceDirectory>java< /sourcedirectory> <resources> <resource> <directory>java</dire
                ctory> </resource> </resources> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactid>maven-compiler-plugi
     N</artifactid>           <version>2.3</version> <configuration> <encoding>ut F-8</encoding> <source>1.8</source> <target>1.8</target > </configuration> </plugin> </plugins> </build> & lt;dependencies> <dependency> <groupId>org.apache.ant</groupId> <a Rtifactid>ant</artifactid> <version>1.9.5</version> </dependency> & Lt;dependency> <groupId>org.apache.ant</groupId> <artifactid>ant-apache-log4j </artifactId> <version>1.9.5</version> </dependency> <dependency&gt
            ;
            <groupId>org.apache.ant</groupId> <artifactId>ant-commons-logging</artifactId> <version>1.9.5</version> </dependency> <dependency> &LT;GROUPID&GT;JAVAX.XM L.rpc</groupid> <artifactId>javax.xml.rpc-api</artifactId> <version>1.1&lt
            ;/version> </dependency> <dependency> <groupId>wsdl4j</groupId> <artifactId>wsdl4j</artifactId> <version>1.6.2</version> </depende ncy> <dependency> <groupId>org.eclipse.jdt.core.compiler</groupId> &L T;artifactid>ecj</artifactid> <version>4.4</version> </dependency> < /dependencies> </project>
third, import IntelliJ idea

(1) Import Maven Project

Open IntelliJ Idea, select Import Project, select/yourpath/tomcat9/pom.xml in the popup box, and continue next until finish

(2) Modify JDK version

Menu bar File->project strucuture->project->project SDK, is it true that JDK 1.8



(3) Setting the startup item

menu bar Run->edit configurations, upper left corner of the + sign, and then select Application Name: Can be random, such as Tomcat_9_run Main Class: Select Org.apache.catalina.startup.Bootstrap VM options: Fill-dcatalina.home= "/yourpath/tomcat9"



(4) Delete WebApps content

Put the contents of the/yourpath/tomcat9/webapps folder, create a new demo folder, and create a new index.html file under the Demo folder, as the test example

<p>hello! This is my Tomcat 9</p>

PS: Here to explain why the contents of the WebApps all removed, because I use MAVEN to build some classes of dependency has not been resolved, so the tomcat comes with the example of some configuration classes can not be loaded, the following will cause an error. As a study this has little impact, and the subsequent free time to solve the problem. iv. Change of source code

Some of the code in Tomcat9 uses Compileroptions.version_1_9 to determine the Java Virtual machine version, which involves the 1.9 version of the JVM, which I can't recognize on my machine.

In the Java/org/apache/jasper/compiler/jdtcompiler.java class to find the above code, delete it, a total of 3. Five, compile

In IntelliJ idea, the right maven Project->lifecycle->compile is compiled.

If you see the following output information, the compilation is successful.

[INFO]
Scanning for projects ...                                                                         
[INFO] [INFO]------------------------------------------------------------------------[INFO] Building Tomcat9 9.0 [INFO]-- ----------------------------------------------------------------------[INFO] [INFO]---maven-resources-plugin : 2.6:resources (default-resources) @ Tomcat9.0---[WARNING] Using platform encoding (UTF-8 actually) to copy filtered Res
Ources, i.e. build is platform dependent! [INFO] Copying 1851 resources [INFO] [INFO]---maven-compiler-plugin:2.3:compile (default-compile) @ Tomcat9.0---[info] Compi Ling 1589 source Files to/users/linxiaodong/lxd/source-code-analysis/tomcat9/target/classes [INFO]----------------- -------------------------------------------------------[INFO] BUILD SUCCESS [INFO]------------------------------- -----------------------------------------[INFO] Total time:17.299 s [info] finished at:2017-05-30t22:02:39+08:00 [ INFO] Final Memory:24m/666m [INFO]------------------------------------------------------------------------Process finished with Exit Code 0
Vi.. Operation

Run the Tomat program in IntelliJ idea and enter it in the browser

Localhost:8080/demo

You can see your new index.html Web page.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.