本文主要参考了文章http://blog.csdn.net/zhangjikuan/article/details/52594828,但发现有些不足。现在补充
tomcat8.5源码分析(一):导入eclipse
SVN客户端下载源代码
配置ant
关于build 主要还是要参考官方网站
修改 base.path=E:/J2EE/tomcat/libraries-tomcat8.0
在tomcat目录下执行
~/Downloads/apache-ant-1.9.7/bin/ant ide-eclipse
报错log如下:
downloadzip: [get] Getting: https://objenesis.googlecode.com/files/objenesis-1.2-bin.zip [get] To: /Users/jikuan.zjk/tomcat-build-libs/download-1580874369.zip [get] Error opening connection java.io.FileNotFoundException: https://objenesis.googlecode.com/files/objenesis-1.2-bin.zip [get] Error opening connection java.io.FileNotFoundException: https://objenesis.googlecode.com/files/objenesis-1.2-bin.zip [get] Error opening connection java.io.FileNotFoundException: https://objenesis.googlecode.com/files/objenesis-1.2-bin.zip [get] Can't get https://objenesis.googlecode.com/files/objenesis-1.2-bin.zip to /Users/jikuan.zjk/tomcat-build-libs/download-1580874369.zip BUILD FAILED /Users/jikuan.zjk/Documents/workspace/apache-tomcat-8.5.4-src/build.xml:2637: The following error occurred while executing this line: /Users/jikuan.zjk/Documents/workspace/apache-tomcat-8.5.4-src/build.xml:2741: Can't get https://objenesis.googlecode.com/files/objenesis-1.2-bin.zip to /Users/jikuan.zjk/tomcat-build-libs/download-1580874369.zip
原因是Google下载不下来objenesis-1.2.jar包 。
类似这种问题,把objenesis-1.2 放到maven中下载下来,然后复制到 目标文件夹中去。具体路径、文件夹名称、版本号可以参考ant配置文件build.properties。
~/Downloads/apache-ant-1.9.7/bin/ant ide-eclipse
这时候就会转换成功了,转换成了eclipse工程,会发现tomcat源码文件下会出现.classpath 和.project文件
导入工程
file->import->Existing Project into workspace->选择工程
这样会有错误,是没有导入jar包的问题 ,看图说话
配置变量即可,科科。。。
如果右击工程时没有build path 修改.project文件,有的话忽略
<?xml version="1.0" encoding="UTF-8"?> <projectDescription> <name>apache-tomcat-8.5.4-src</name> <comment></comment> <projects> </projects> <buildSpec> </buildSpec> <natures> <nature>org.eclipse.jdt.core.javanature</nature> </natures> </projectDescription>
主要是添加org.eclipse.jdt.core.javanature,要不然找不到build path,jar包也加不进来
启动
找到java/org.apache.catalina.startup/Bootstrap.java文件,右击->run as->run configurations->在java application里选择start-tomcat(自动生成的)
错误log如下:
九月 20, 2016 12:21:13 下午 org.apache.catalina.startup.CatalinaProperties loadProperties警告: Failed to load catalina.properties九月 20, 2016 12:21:13 下午 org.apache.catalina.startup.Catalina load警告: Unable to load server configuration from [/Users/jikuan.zjk/Documents/workspace/tomcat-8.5.x/output/build/conf/server.xml]九月 20, 2016 12:21:13 下午 org.apache.catalina.startup.Catalina load警告: Unable to load server configuration from [/Users/jikuan.zjk/Documents/workspace/tomcat-8.5.x/output/build/conf/server.xml]九月 20, 2016 12:21:13 下午 org.apache.catalina.startup.Catalina start严重: Cannot start server. Server instance is not configured.
可见是在output文件加下找到build/conf/server.xml文件,output是ant编译时候编译出来的,在源码文件夹下是有个conf文件夹的,里面有server.xml
在output文件夹下创建build/conf/并把server.xml复制进去
重新启动,OK,启动成功
信息: Server startup in 176 ms
现在启动时没问题了,但是还不可以对外提供服务