關于tomcat源碼的編譯和環境搭建自己也是拖了一段時間,今天還是硬着頭皮來做一做,還是有所收獲。
tomcat源碼的編譯還是首選ant,作為apache的頂級項目ant,可以參見下面的連結進行下載下傳,下載下傳一個二進制運作包即可。
http://ant.apache.org/bindownload.cgi
然後就需要在path中配置了。
簡單的校驗
C:\Users\jeanron>ant -version
Apache Ant(TM) version 1.9.5 compiled on May 31 2015
然後下載下傳tomcat的源碼,在tomcat.apache.org中可以選擇,為了相容jdk版本,我選擇的是tomcat7
下載下傳解壓後,需要在目錄中修改下面的檔案。
重命名build.properties.default 為build.properties
然後在build.properties中修改base.path
預設是:
base.path=/usr/share/java
因為本地是windows環境,是以修改為下面的樣式。
base.path=D:/tomcat7/output
根據官方建議,最好還是build.properties中配置下面的proxy配置。自己在本地比較了下,不配置基本上界面沒什麼反應,配置之後速度還是很快的。
proxy.use=on
proxy.host=proxy.domain
proxy.port=8080
proxy.user=username
proxy.password=password
當然了jdk版本也是必須的,我在本地使用的1.6.
然後就開始build。
D:\tomcat7>ant
Buildfile: D:\tomcat7\build.xml
build-prepare:
[mkdir] Created dir: D:\tomcat7\output\classes
[mkdir] Created dir: D:\tomcat7\output\build
[mkdir] Created dir: D:\tomcat7\output\build\bin
[mkdir] Created dir: D:\tomcat7\output\build\conf
[mkdir] Created dir: D:\tomcat7\output\build\lib
[mkdir] Created dir: D:\tomcat7\output\build\logs
[mkdir] Created dir: D:\tomcat7\output\build\temp
[mkdir] Created dir: D:\tomcat7\output\build\webapps
download-compile:
testexist:
[echo] Testing for D:/tomcat7/output/tomcat-native-1.1.33/tomcat-native.ta
r.gz
downloadfile-2:
proxyflags:
setproxy:
[echo] Using proxy.domain:8080 to download http://www.apache.org/dist/tomca
t/tomcat-connectors/native/1.1.33/source/tomcat-native-1.1.33-src.tar.gz
trydownload.check:
trydownload:
[get] Getting: http://www.apache.org/dist/tomcat/tomcat-connectors/native/
1.1.33/source/tomcat-native-1.1.33-src.tar.gz
[get] To: D:\tomcat7\output\download-2067852301.tmp
當然了build的過程也不是一帆風順的,比如網絡的問題,直接逾時退出。
D:\tomcat7\build.xml:2927: java.net.ConnectException: Connection timed out: conn
ect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketI
mpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.ja
va:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocket
Impl.java:200)
在另外一台環境中使用jdk 1.7的版本,竟然在build的時候有些問題。
....
[javac] ^
[javac] D:\tomcat7\output\tomcat7-deps\dbcp\src\java\org\apache\tomcat\dbcp\
dbcp\datasources\PerUserPoolDataSource.java:60: 錯誤: PerUserPoolDataSource不是
抽象的, 并且未覆寫CommonDataSource中的抽象方法getParentLogger()
[javac] public class PerUserPoolDataSource
dbcp\datasources\SharedPoolDataSource.java:52: 錯誤: SharedPoolDataSource不是抽
象的, 并且未覆寫CommonDataSource中的抽象方法getParentLogger()
[javac] public class SharedPoolDataSource
[javac] 注: 某些輸入檔案使用或覆寫了已過時的 API。
[javac] 注: 有關詳細資訊, 請使用 -Xlint:deprecation 重新編譯。
[javac] 注: 某些輸入檔案使用了未經檢查或不安全的操作。
[javac] 注: 有關詳細資訊, 請使用 -Xlint:unchecked 重新編譯。
[javac] 15 個錯誤
[javac] 1 個警告
BUILD FAILED
D:\tomcat7\build.xml:2686: The following error occurred while executing this lin
e:
D:\tomcat7\build.xml:2790: Compile failed; see the compiler error output for det
ails.
Total time: 1 minute 21 seconds
最後換成1.6就沒有問題了。
build:
[javac] Compiling
31 source files to C:\tomcat7\output\jdbc-pool\classes
[jar] Building
jar: C:\tomcat7\output\jdbc-pool\tomcat-jdbc.jar
[copy] Copying 1
file to C:\tomcat7\output\build\lib
BUILD SUCCESSFUL
Total time: 2 minutes 1 second
源碼的編譯高一段落,接下來就是在eclipse中導入了,
可以直接建立一個java project,然後選擇tomcat源碼的路徑即可。導入源碼的截圖如下:
當然了還有依賴的包。
還有幾個依賴的包,比如ant...
不過直接通過eclipse還是能夠順利啟動的
INFO: Deploying web application
directory C:\tomcat7\webapps\ROOT
Jun 29, 2015 11:47:20 PM
org.apache.catalina.startup.TldConfig execute
INFO: At least one JAR was scanned
for TLDs yet contained no TLDs. Enable debug logging for this logger for a
complete list of JARs that were scanned but no TLDs were found in them.
Skipping unneeded JARs during scanning can improve startup time and JSP
compilation time.
org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application
directory C:\tomcat7\webapps\ROOT has finished in 27 ms
org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler
["http-bio-8080"]
["ajp-bio-8009"]
org.apache.catalina.startup.Catalina start
INFO: Server startup in 626 ms