步骤1:
下载源码 Tomcat 8 官网下载:http://tomcat.apache.org/download-80.cgi
步骤2:
进入eclipse 工作空间workspace,创建Tomcat8 文件
下载的zip 文件在其中进行解压:
步骤3:
将解压后的所有目录文件放到Tomcat8 下
步骤4:
在tomcat8 下创建maven项目所依赖的pom.xml文件,文件内容如下
<?xml version="1.0" encoding="utf-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.tomcat</groupId>
<artifactId>Tomcat8.0</artifactId>
<name>Tomcat8.0</name>
<version>8.0</version>
<build>
<finalName>Tomcat8.0</finalName>
<!-- 指定源文件为java 、test -->
<sourceDirectory>java</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<resources>
<resource>
<directory>java</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>test</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>c</artifactId>
<version>2.3</version>
<configuration>
<encoding>UTF-8</encoding>
<!-- 指定jdk 编译 版本 ,没装jdk 1.7的可以变更为1.6 -->
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<!-- 添加tomcat8 所需jar包依赖 -->
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</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>
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>4.6.1</version>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.3</version>
</dependency>
</dependencies>
</project>
步骤5 :
打开eclipse ,以maven 项目形式导入工程
步骤 6:
更新maven依赖,启动源码
步骤7:
启动日志的输出,浏览器进行访问,验证启动效果
解决:Bootstrap 启动时。
提示:Servlet.service() for servlet [jsp] in context with path [] threw exception [java.lang.NullPointerException] with root cause
java.lang.NullPointerException
at org.apache.jsp.index_jsp._jspService(index_jsp.java:427)
错误说明:tomcat 默认项目ROOT 缺少jsp 标签解析类。我把tomcat8容器源码已经全部导入,但还是提示文件tomcat 依赖的jar文件找不到。
解决版本:找到对应tomact 版本,拷贝器lib 文件夹复制到tomcat 源码/webapp/ROOT/WEB-INF.如截图所示: