一、下载Tomcat7源码
从官网上下载Tomcat源码, http://mirror.bit.edu.cn/apache/tomcat/tomcat-7/v7.0.70/src/apache-tomcat-7.0.70-src.zip
下载之后,将源码解压后重名为tomcat-src,放在E盘的tomcat7目录下.
二、安装Ant
因Tomcat源码需要ant编译,所以需要安装Ant,从官网下载后解压,并配置环境变量即可.
三、安装JDK6
tomcat7的编译需要JDK6的环境,JDK7以及以上,ant 编译时会报错.
四、用Ant工具编译Tomcat源码
打开cmd命令行工具,进入tomcat源码目录,输入ant ide-eclipse ,然后按下Enter键,会自动下载编译需要的依赖包.
- testexist:
- [echo] Testing for C:\Users\yulei/tomcat-build-libs/objenesis-1.2/objenesis-1.2.jar
- downloadzip:
- [get] Getting: https://objenesis.googlecode.com/files/objenesis-1.2-bin.zip
- [get] To: C:\Users\yulei\tomcat-build-libs\download-1649634615.zip
- [get] Error getting https://objenesis.googlecode.com/files/objenesis-1.2-bin.zip to C:\Users\yulei\tomcat-build-libs\download-16496
- BUILD FAILED
- E:\tomcat7\tomcat_src\build.xml:2697: The following error occurred while executing this line:
- E:\tomcat7\tomcat_src\build.xml:2848: java.net.ConnectException: Connection timed out: connect
- at java.net.PlainSocketImpl.socketConnect(Native Method)
- at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
- at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
- at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
- at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
- at java.net.Socket.connect(Socket.java:529)
- at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:570)
- at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:141)
- at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
- at sun.net.www.http.HttpClient.openServer(HttpClient.java:411)
- at sun.net.www.http.HttpClient.openServer(HttpClient.java:525)
- at sun.net.www.protocol.https.HttpsClient.
(HttpsClient.java:272) - at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:329)
- at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:172)
- at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:923)
- at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:158)
- at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:133)
- at org.apache.tools.ant.taskdefs.Get$GetThread.openConnection(Get.java:728)
- at org.apache.tools.ant.taskdefs.Get$GetThread.get(Get.java:641)
- at org.apache.tools.ant.taskdefs.Get$GetThread.run(Get.java:631)
- Total time: 1 minute 58 seconds
可以看见,编译报错了,是因为从国外网站下载依赖的objenesis-1.2-bin.zip超时了,导致编译失败.
解决办法,下载objenesis-1.2-bin.zip文件,这里为了方便,为大家提供了下载地址:http://pan.baidu.com/s/1kUWtA8v
将其解压后放在C:\Users\yulei\tomcat-build-libs 目录下面
再次运行ant ide-eclipse 命名就会编译成功了
编译成功后,会生成Eclipse的项目文件(.classpath等),如下图:
五、将Tomcat7源码导入MyEclipse
以此类推,把余下的Tomacat依赖包配置好。TOMCAT_LIB_BASE 配置的地址是:C:/Users/yulei/tomcat-build-libs
六、运行Tomcat
右键Tomcat工程,Run As --->Java Application, 选择Bootstrap.
点击OK,出现如下选项:
选择start-tomcat,后命令行出现如下信息:
- 九月 05, 2016 11:21:21 下午 org.apache.catalina.startup.CatalinaProperties loadProperties
- WARNING: Failed to load catalina.properties
- 九月 05, 2016 11:21:21 下午 org.apache.catalina.startup.Catalina load
- WARNING: Unable to load server configuration from [D:\CBSS\code\tomcat-7.0.x\output\build\conf\server.xml]
- 九月 05, 2016 11:21:21 下午 org.apache.catalina.startup.Catalina load
- WARNING: Unable to load server configuration from [D:\CBSS\code\tomcat-7.0.x\output\build\conf\server.xml]
- 九月 05, 2016 11:21:21 下午 org.apache.catalina.startup.Catalina start
- SEVERE: Cannot start server. Server instance is not configured.
表示,tomcat服务没有跑起来,别着急,用Ant deploy一下你的tomcat工程.
deploy成功之后,然后再运行你的tomcat,会出现如下信息,表示Tomcat服务已成功启起来:
访问http://localhost:8080