前提环境,安装和配置好java1.8+环境,maven,IDEA

1.下载Tomcat源代码:https://tomcat.apache.org/download-80.cgi#8.5.35

2.创建pom.xml

需要通过Maven组织文件,因此需要在apache-tomcat-8.5.35-src根目录下创建目录中新建catalina-home目录和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.5</artifactId>
<name>Tomcat8.5</name>
<version>8.5</version> <build>
<finalName>Tomcat8.5</finalName>
<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>maven-compiler-plugin</artifactId>
<version>2.3</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.4</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>
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>4.5.1</version>
</dependency> </dependencies>
</project>

apache-tomcat-8.0.53-src目录中的conf和webapps文件夹复制到catalina-home目录中

三、配置IDEA运行项目

Main class设置为org.apache.catalina.startup.Bootstrap

添加VM options

-Dcatalina.home=catalina-home
-Dcatalina.base=catalina-home
-Djava.endorsed.dirs=catalina-home/endorsed
-Djava.io.tmpdir=catalina-home/temp
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.util.logging.config.file=catalina-home/conf/logging.properties

说明:如果编译build的时候出现Test测试代码报错,注释该代码即可。本文中的Tomcat源码util.TestCookieFilter类会报错,将其注释即可

运行项目,访问http://localhost:8080,得到结果:

原因是我们直接启动org.apache.catalina.startup.Bootstrap的时候没有加载org.apache.jasper.servlet.JasperInitializer,从而无法编译JSP。解决办法是在tomcat的源码org.apache.catalina.startup.ContextConfig中的configureStart函数中手动将JSP解析器初始化:

protected synchronized void configureStart() {
// Called from StandardContext.start() if (log.isDebugEnabled()) {
log.debug(sm.getString("contextConfig.start"));
} if (log.isDebugEnabled()) {
log.debug(sm.getString("contextConfig.xmlSettings",
context.getName(),
Boolean.valueOf(context.getXmlValidation()),
Boolean.valueOf(context.getXmlNamespaceAware())));
} webConfig(); context.addServletContainerInitializer(new JasperInitializer(), null); if (!context.getIgnoreAnnotations()) {
applicationAnnotationsConfig();
}
if (ok) {
validateSecurityRoles();
} // Configure an authenticator if we need one
if (ok) {
authenticatorConfig();
} // Dump the contents of this pipeline if requested
if (log.isDebugEnabled()) {
log.debug("Pipeline Configuration:");
Pipeline pipeline = context.getPipeline();
Valve valves[] = null;
if (pipeline != null) {
valves = pipeline.getValves();
}
if (valves != null) {
for (int i = 0; i < valves.length; i++) {
log.debug(" " + valves[i].getClass().getName());
}
}
log.debug("======================");
} // Make our application available if no problems were encountered
if (ok) {
context.setConfigured(true);
} else {
log.error(sm.getString("contextConfig.unavailable"));
context.setConfigured(false);
} }

修改完后,项目再启动,我们再在浏览器访问http://localhost:8080/ ,就可以看到我们所熟悉的经典欢迎页面了

 

IDEA运行tomcat8.5.35源代码的更多相关文章

  1. 【Spark Core】任务运行机制和Task源代码浅析1

    引言 上一小节<TaskScheduler源代码与任务提交原理浅析2>介绍了Driver側将Stage进行划分.依据Executor闲置情况分发任务,终于通过DriverActor向exe ...

  2. CentOS7运行Tomcat8时启动慢,访问总是转圈,但是过一会又好了

    我一开始遇到这个问题的时候也是懵逼的. 这叫什么问题... 描述一下,当输入命令启动tomcat之后,访问网站总是不能访问,但是5.6分钟之后又好了,有时候好,有时候不行. 遇到这样的问题运用以下的方 ...

  3. Tomcat7调试运行环境搭建与源代码分析入门

    1. 需要准备好下面这些工具 JDK 1.6+ Maven 2或3 TortoiseSVN 1.7+ (从1.7开始”.svn”目录集中放在一处了,不再每个目录下都放一份) Eclipse 3.5+ ...

  4. centOS7.5上部署server jre1.8.0_192 tomcat-8.5.35 mysql-8.0.13

  5. Tomcat Stack-8.0.35 (OpenLogic CentOS7.2)

       平台: CentOS 类型: 虚拟机镜像 软件包: apache2.4.20 mysql5.6.30 tomcat8.0.35 apache application server basic s ...

  6. 开启Tomcat APR运行模式,优化并发性能

    Tomcat支持三种接收请求的处理方式:BIO.NIO.APR 1>.BIO模式:阻塞式I/O操作,表示Tomcat使用的是传统JavaI/O操作(即Java.io包及其子包).Tomcat7以 ...

  7. Python实现中文字幕雨+源代码

    写在前面的一些P话: 最近浏览了很多关于用Python和Pygame实现代码雨的案例,发现很多都是没有深入讲解代码的整个实现过程,从0到1教会你制作中文文字雨. 然后在介绍的过程中,我也将深入介绍Py ...

  8. Android:基于Eclipse编译调试系统级应用源代码

    一.      概要描述 在使用Eclipse导入android工程源代码以后,我们可以使用ddms调试和跟踪源代码. 本文讲述动态调试源代码和静态调试源代码的两种方法,避免build system. ...

  9. Centos6.8 安装tomcat8.5.11

    1.下载 安装包 wget http://mirrors.aliyun.com/apache/tomcat/tomcat-8/v8.5.11/bin/apache-tomcat-8.5.11.tar. ...

随机推荐

  1. epoll_wait惊群问题

    项目接入层用的模型是,主线程创建listenfd,传入6个子线程,每个子线程一个事件循环,epoll_wait这个listenfd. 如果是listenfd,则epoll_wait返回调用accept ...

  2. DG增量恢复

    本篇文档: 讲述DG环境出现GAP归档缝隙,且主库的该归档日志被删除的情况下,快速恢复DG的连通性 流程讲述: >明确主库增量备份起点 scn 查询备库控制文件current scn ,及v$d ...

  3. jQuery的文件引入、入口函数以及js对象和jquery对象之间的互相转换

    JavaScript与jquery的区别 JavaScript是一门编程语言,用来编写客户端浏览器脚本. jQuery是javascript的一个库,包含多个可重用的函数,用来辅助简化javascri ...

  4. html+css实现小米商城首页静态页面

    学了一个星期的html和css,用新学的东西写点东西,仿照小米商城的首页按照它的页面布局盗用它的图片写了个小米商城的静态页面. 源代码:链接:https://pan.baidu.com/s/1qf63 ...

  5. Python之路,第十七篇:Python入门与基础17

    python3  面向对象编程 面向对象编程 什么是对象? 一切皆对象: 面向对象是思想: 描述思想的语言有:C++/Java/Python/Swift/C# 两个概念: 类  class 对象 ob ...

  6. 给电脑换源 npm 国内镜像 cnpm

    (1)通过 config 配置指向国内镜像源 npm config set registry http://registry.cnpmjs.org //配置指向源 npm info express   ...

  7. HDU 1686:Oulipo(KMP模板,子串出现次数)

    Oulipo Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  8. php基础-3

    php的数据类型 字符串 字符串的声明:$str = "aaa"; 字符串的方法 strpos(str, find_str):该方法在一个字符串中查找需要查找的字符串,并回来该字符 ...

  9. Go Example--range

    package main import "fmt" func main() { nums := []int{2,3,4} sum :=0 //rang 遍历切片 for _,num ...

  10. this关键字的使用8/22

    实质就是:this代表当前对象目录: 1.this(name) 调用同一个类中参数为 public Person(String name)这个构造方法 2.this.say() 同一个类中,某一个方法 ...