2014-02-27 16:18:05

Tomcat7源码eclipse(mvn)

打包好的eclipse项目下载:Tomcat7.0.zip

需要先分别Tomcat7二进制文件下载:apache-tomcat-7.0.52.zip 和 Tomcat7源文件: apache-tomcat-7.0.52-src.zip。然后需要安装好maven环境:Maven。参考原文:http://zhh2009.iteye.com/blog/1557891

新建一个Tomcat7目录,解压apache-tomcat-7.0.52.zip到Tomcat7目录并更改apache-tomcat-7.0.52为 trunk,解压apache-tomcat-7.0.52-src.zip到Tomcat7目录并更改apache-tomcat-7.0.52-src为launch。用这个二进制分发包而不是从源代码构建只是为了节省时间,直接用它conf目录里面的配置文件和webapps下的例子。

新建pom.xml,内容:

<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/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>org.apache.tomcat</groupId>
	<artifactId>Tomcat7.0</artifactId>
	<name>Tomcat7.0</name>
	<version>7.0</version>
	<build>
		<finalName>Tomcat7.0</finalName>
		<sourceDirectory>trunk/java</sourceDirectory>
		<testSourceDirectory>trunk/test</testSourceDirectory>
		<resources>
			<resource>
				<directory>trunk/java</directory>
			</resource>
		</resources>
		<testResources>
			<testResource>
				<directory>trunk/test</directory>
			</testResource>
		</testResources>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>2.3</version>
				<configuration>
					<source>1.6</source>
					<target>1.6</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.4</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.eclipse.jdt.core.compiler</groupId>
			<artifactId>ecj</artifactId>
			<version>3.7.2</version>
		</dependency>
		<dependency>
			<groupId>ant</groupId>
			<artifactId>ant</artifactId>
			<version>1.7.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>
	</dependencies>
</project>

在命令行窗口中进入Tomcat7目录,执行 mvn eclipse:eclipse 就可以转成eclipse工程项目了,然后打开eclipse,点"File->Import->General->Existing Projects into Workspace",最后打开Tomcat7就能看到Tomcat7.0这个项目了。

在Eclipse中打开org.apache.catalina.startup.Bootstrap类,

在编辑区右击,点"Run As->Run configurations",然后双击"Java Aplication"就会出来一个新的"Bootstrap",

选中它,在右边点击"Arguments"那一栏,把下面的内容copy到"VM arguments"中:

-Dcatalina.home=launch -Dcatalina.base=launch -Djava.endorsed.dirs=launch/endorsed -Djava.io.tmpdir=launch/temp -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=launch/conf/logging.properties
除上面这种方式外,这里还有一个Eclipse的launch脚本: start-tomcat7.launch
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/Tomcat7.0/trunk/java/org/apache/catalina/startup/Bootstrap.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.apache.catalina.startup.Bootstrap"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="start"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="Tomcat7.0"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dcatalina.home=launch -Dcatalina.base=launch -Djava.endorsed.dirs=launch/endorsed -Djava.io.tmpdir=launch/temp -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=launch/conf/logging.properties"/>
</launchConfiguration>
发表回复