tomcat源码下载运行

 tomcat 源码下载及本地运行

 

Tomcat 主干分支地址:

Git 地址 :https://github.com/apache/tomcat.git

Svn地址:http://svn.apache.org/repos/asf/tomcat/trunk

 

本文用svn (svn下载的较快些,好用点)

 

1. 预备---可先阅读官方文件 http://svn.apache.org/repos/asf/tomcat/trunk/BUILDING.txt

   (1)  安装 JDK,并配置好 环境变量。  [ 1.8.0_20]

(http://www.oracle.com/technetwork/java/javase/downloads/index.html)

检验安装及环境变量




   (2)  安装 tortoisesvn                 [TortoiseSVN 1.8.6]

               (https://tortoisesvn.net/) 

   (3) 下载,安装ant,并配置好 环境变量。 [apache-ant-1.9.6]

               (http://ant.apache.org/bindownload.cgi)

检验安装及环境变量

 

(4)下载 eclipse              [Mars.2 Release (4.5.2)]

        (http://www.eclipse.org/downloads/)

 

注: 不考虑兼容性,稳定性,纯属技术性学习,都应该选择最新的版本

 

下载此目录http://svn.apache.org/repos/asf/tomcat/trunk 所有代码到本地

     假设目录为  ${tomcat-src}

复制  ${tomcat-src}/build.properties.default 到当前目录,并改扩展后缀命名为

build.properties

在此文件找到 base.path= 配置项,

原来为: base.path=${user.home}/tomcat-build-libs

${user.home} 这个目录可改下,改为自己喜欢的目录, 该目录会下载并存放tomcat依赖的其它jar

 

若为公司网络,存在代理,则需要在build.properties配置 如下项

        proxy.use=true

        proxy.host=proxy.domain

        proxy.port=8080

        proxy.user=username

        proxy.password=password

 

 在${tomcat-src} 目录下依次执行如下两个命令

ant

ant ide-eclipse

 

若存在执行 ant命令时,下载过程报错,即下载第三方Jar失败,可以手动下载,按照指定的目录放。

 

比如:

downloadzip:

      [get] Getting: https://objenesis.googlecode.com/files/objenesis-1.2-bin.zi

p

      [get] To: E:\osource\svn\apache\tomcat\trunk\3rd\tomcat-build-libs\downloa

d-157966192.zip

      [get] Error getting https://objenesis.googlecode.com/files/objenesis-1.2-b

in.zip to E:\osource\svn\apache\tomcat\trunk\3rd\tomcat-build-libs\download-1579

66192.zip

 

BUILD FAILED

E:\osource\svn\apache\tomcat\trunk\build.xml:2840: The following error occurred

while executing this line:

E:\osource\svn\apache\tomcat\trunk\build.xml:2944: java.net.ConnectException: Co

nnection timed out: connect

 

1.可以手动打开浏览器 https://objenesis.googlecode.com/files/objenesis-1.2-bin.zi

P下载。

当然此处googlecode的访问,需要一定技术,实在不行,也可 百度 objenesis

网上有下的。

 

具体下载的第三jar放到哪。可参考build.properties文件。比如:

 

# ----- objenesis, used by EasyMock, version 1.2 or later -----

objenesis.version=1.2

objenesis.home=${base.path}/objenesis-${objenesis.version}

objenesis.loc=https://objenesis.googlecode.com/files/objenesis-${objenesis.version}-bin.zip

objenesis.jar=${objenesis.home}/objenesis-${objenesis.version}.jar

 

其中${base.path}为  

base.path=${user.home}/tomcat-build-libs   ({user.home}是否改了?改了就换下..)

其中 ${objenesis.version}  以 1.2  替换

Jar网上存在的地址为:

https://objenesis.googlecode.com/files/objenesis-1.2-bin.zip

 

本地需要放的地址为

${base.path}/objenesis-1.2/objenesis-1.2.jar



  

 

${tomcat-src}这个目录会有 

.classpath

.project 这两个文件,因此可以导入eclipse

 

以Exiting Projects into Workspace

导入eclipse 工程  

 

此时发现报错如下

DescriptionResourcePathLocationType

Unbound classpath variable: 'ANT_HOME/lib/ant.jar' in project 'tomcat-9.0.x'tomcat-9.0.xBuild pathBuild Path Problem


 

打开 .classpath 文件 发现



 

解决方法:

Window->Preferences->java->build path->Classpath Variables

选择右边 New  添加两个classpath 变量

Ant home目录


上面配置的tomcat依赖的第三方目录base.path=${user.home}/tomcat-build-libs


  

 

若不想配置变量到eclipse,也可以直接改  .classpath文件。比如

 

<classpathentry kind="var" path="TOMCAT_LIBS_BASE/ecj-4.5.1/ecj-4.5.1.jar"/>

改为

<classpathentry 

kind="lib" path="E:/osource/svn/apache/tomcat/trunk/3rd/tomcat-build-libs/ecj-4.5.1/ecj-4.5.1/ecj-4.5.1.jar"/>

 

 

 

5

Eclipse中, 选择该工程文件下  build.xml

选择右键

 

Ant build

     [echo] Building Tomcat JDBC pool libraries

prepare:

download:

build-src:

build:

compile-webapp-examples:

deploy:

examples-sources:

BUILD SUCCESSFUL

Total time: 2 seconds

 

此时output目录下有对应的编译打包的文件, 运行的所有文件都以 output目录下的为准,比如配置文件

output\build\conf\server.xml

 

 

运行

org.apache.catalina.startup.Bootstrap

下的 main方法

启动  start-tomcat

 

三月 31, 2016 9:40:32 下午 org.apache.catalina.startup.Catalina start

信息: Server startup in 3611 ms

 

浏览器访问

http://localhost:8080/

 

官方样例学习:

 http://localhost:8080/examples/

 

猜你喜欢

转载自ghods.iteye.com/blog/2287889