tomcat源碼閱讀--eclipse源碼搭建

 

寒暄部分:

一直說閱讀tomcat源碼但始終沒有着手去做這件事,但感覺很有必要,今天想回過頭來去做這件事情。

今天就開始在本地eclipse中搭建閱讀tomcat源碼的環境。

本地環境搭建:

first:

源碼下載:首先要到官網下載tomcat源碼如果怕麻煩可以到其它博客的下載:tomcat源碼下載路徑 ps:本人上傳的

second:

源碼下載了要用什麼構建編譯工具管理這個問題很是頭疼,一般都會在這一步放棄了,make ant maven gradle 大部分都是用ant 然後各種操作,到最後都是無疾而終。這邊採用maven(妹問 麥問 不要讀成媽問)

這裏就涉及到了各種工程之間的轉換問題了,eclipse中的普通項目  git項目  maven項目  ,不同項目都會有其對應的標緻文件的,maven 的標緻文件就是pom.xml 這個時候要這解壓後的文件新建一個pom.xml 在這裏面添加所依賴的jar座標了,涉及到了maven的知識不清楚的去複習一下maven的基本使用。

然後再用eclipse 導入,就會發現eclipse會讀到pom.xml文件。這個時候原先下載的源碼就變成了maven項目了。

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>org.apache</groupId>
    <artifactId>tomcat</artifactId>
    <name>apache-tomcat-8.5.24</name>
    <version>8.5.24</version>

    <build>
        <finalName>Tomcat-8.5.24</finalName>
        <sourceDirectory>java</sourceDirectory>
        <testSourceDirectory>test</testSourceDirectory>
        <resources>
            <resource>
                <directory>java</directory>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>test</directory>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.easymock</groupId>
            <artifactId>easymock</artifactId>
            <version>3.4</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant</artifactId>
            <version>1.10.0</version>
        </dependency>
        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
            <version>1.6.2</version>
        </dependency>
        <dependency>
            <groupId>javax.xml</groupId>
            <artifactId>jaxrpc</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jdt.core.compiler</groupId>
            <artifactId>ecj</artifactId>
            <version>4.6.1</version>
        </dependency>
    </dependencies>
</project>  

導入maven項目,因爲有些測試類依賴了examples目錄的類,因此把apache-tomcat-8.5.24-src\webapps\examples\WEB-INF\classes目錄在開發工具上面設置爲java源文件,編譯的class輸出目錄設爲classes,如下圖所示

final

代碼倉庫的利用:

如果說你閱讀源碼什麼都不註釋什麼都不動那就沒意思了,但改過後都不知道自己都幹了些啥,所以源碼備份很重要,所以選擇上傳到 github 或者是碼雲 這裏涉及到了  git的使用,有時間可以學習一下。git小結

參考資料:

https://blog.csdn.net/Dwade_mia/article/details/79051370

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章