Tomcat源码解析(一)下载源码与导入eclipse

来源:互联网 发布:js append html 样式 编辑:程序博客网 时间:2024/06/07 03:54

   自从写web程序以来,web程序是如何在Tomcat中运行的一直困惑着我,不知道底层的运行机制是无法真正理解web的,所以就开始研究Tomcat源码,Tomcat是一个轻量级的Java服务器,再结合《How Tomcat works》和网上大牛博客之后,也算知道了内部的运行架构。

    首先去官网下载Tomcat源码,我下载的是apache-tomcat-7.0.63-src(在这里下载),因为源码使用ant和maven管理的,所以要用ant或者maven编译为eclipse工程。ant方法编译时有好多错误,又麻烦,所以这里介绍用maven将其编译。

    首先将下载的apache-tomcat-7.0.50-src.tar.gz解压到tomcat目录中,然后在tomcat目录中创建一个pom.xml文件,内容如下:

[html] view plain copy
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  2.          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  
  3.   
  4.     <modelVersion>4.0.0</modelVersion>  
  5.     <groupId>net.imtiger</groupId>  
  6.     <artifactId>tomcat-study</artifactId>  
  7.     <name>Tomcat 7.0 Study</name>  
  8.     <version>1.0</version>  
  9.     <packaging>pom</packaging>  
  10.   
  11.     <modules>  
  12.         <module>apache-tomcat-7.0.63-src</module>  
  13.     </modules>  
  14. </project>  
然后在apache-tomcat-7.0.63-src目录下创建一个pom.xml文件,内容如下:


[html] view plain copy
  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.   
  7.     <modelVersion>4.0.0</modelVersion>  
  8.     <groupId>org.apache.tomcat</groupId>  
  9.     <artifactId>Tomcat7.0</artifactId>  
  10.     <name>Tomcat7.0</name>  
  11.     <version>7.0</version>  
  12.   
  13.     <build>  
  14.         <finalName>Tomcat7.0</finalName>  
  15.         <sourceDirectory>java</sourceDirectory>  
  16.         <testSourceDirectory>test</testSourceDirectory>  
  17.         <resources>  
  18.             <resource>  
  19.                 <directory>java</directory>  
  20.             </resource>  
  21.         </resources>  
  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>2.3</version>  
  32.   
  33.                 <configuration>  
  34.                     <encoding>UTF-8</encoding>  
  35.                     <source>1.6</source>  
  36.                     <target>1.6</target>  
  37.                 </configuration>  
  38.             </plugin>  
  39.         </plugins>  
  40.     </build>  
  41.   
  42.     <dependencies>  
  43.         <dependency>  
  44.             <groupId>junit</groupId>  
  45.             <artifactId>junit</artifactId>  
  46.             <version>4.4</version>  
  47.             <scope>test</scope>  
  48.         </dependency>  
  49.         <dependency>  
  50.             <groupId>ant</groupId>  
  51.             <artifactId>ant</artifactId>  
  52.             <version>1.7.0</version>  
  53.         </dependency>  
  54.         <dependency>  
  55.             <groupId>wsdl4j</groupId>  
  56.             <artifactId>wsdl4j</artifactId>  
  57.             <version>1.6.2</version>  
  58.         </dependency>  
  59.         <dependency>  
  60.             <groupId>javax.xml</groupId>  
  61.             <artifactId>jaxrpc</artifactId>  
  62.             <version>1.1</version>  
  63.         </dependency>  
  64.         <dependency>  
  65.             <groupId>org.eclipse.jdt.core.compiler</groupId>  
  66.             <artifactId>ecj</artifactId>  
  67.             <version>4.2.2</version>  
  68.         </dependency>  
  69.     </dependencies>  
  70. </project>  
最后,在tomcat目录下执行mvn eclipse:eclipse生成Eclipse工程,导入进去即可.
原创粉丝点击