网上看了一些Tomcat调试环境搭建的文章,把简单的事情都复杂化了,总结一下快速搭建调试环境的过程:
1.需要的工具如下:
eclipse3.4
maven2插件:http://m2eclipse.sonatype.org/update/
svn插件:http://subclipse.tigris.org/update_1.4.x
maven2.0.9
2.从eclipse里svn视图中,连接tomcat的SCM,地址为:http://svn.apache.org/repos/asf/tomcat 。进入路径 tc6.0.x/tags,右击TOMCAT_6_0_18选择“检出为”。。。将其检出到自己的eclipse工作空间。(如果此过程中提示出现错误,多重试几次即可)
3.切换回java视图,右击项目名,激活maven2支持。设置项目的java build path 将java和test目录设置为source folders,output folder设置为{project.name}/target/classes。Libraries中,首先add External jars,找到eclipse目录下的plugins/org.eclipse.jdt.core_3.4.2.v_883_R34x.jar,引入之。如果附件 3.gif
4. 其余的jar都交给maven,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</groupId>
<artifactId>tomcat</artifactId>
<name>tomcat</name>
<version>6.0.18</version>
<build>
<sourceDirectory>java</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
</build>
<dependencies>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxrpc-api</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>commons-daemon</groupId>
<artifactId>commons-daemon</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.2.2</version>
<exclusions>
<exclusion>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.7.1</version>
</dependency>
</dependencies>
</project>
5.直接下载tomcat6.0.18的bin版本,解压缩到任意路径,此处假设为{catalina.home}。
6.设置eclipse的Run Configurations,在java application一栏中new 2个,一个叫"tomcat start",一个叫"tomcat stop"(名字随意)。配置如附件 1.gif和2.gif:
Main class:org.apache.catalina.startup.Bootstrap
Program arguments:start (or stop)
VM arguments:-Dcatalina.home="{catalina.home}" (tomcat6.0.18的bin版本的路径)
7. OK了,在eclipse 的 Debug Configurations 中,选择上述new的start或者stop,直接点 Debug按钮运行即可,Console view中即可看到tomcat的启动信息。此时可在jsp编译类(org.apache.jasper.compiler.Compiler)中插入断点,打开IE,随意输入一个已存的jsp的URL,即可进入debug。