IDEA 导入 Tomcat9 源码
源码下载(Source Code Distributions)地址:https://tomcat.apache.org/download-90.cgi
tomcat 和 servlet 以及 jdk 版本的对应关系:http://tomcat.apache.org/whichversion.html
附上搭建好的环境:https://gitee.com/jhxxb/MyTomcat
Maven方式
一、解压源码
在源码根目录新建 home 文件夹,把 conf 文件夹和 webapps 文件夹移动到 home 文件夹里,然后在源码根目录新建 pom.xml 文件(原来为 Ant 工程,这里把它改为 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>tomcat</artifactId>
<name>tomcat</name>
<version>9.0.19</version> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.10.5</version>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.3</version>
</dependency> <!--<dependency>-->
<!--<groupId>javax.xml</groupId>-->
<!--<artifactId>jaxrpc</artifactId>-->
<!--<version>1.1</version>-->
<!--</dependency>-->
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jaxrpc_1.1_spec</artifactId>
<version>2.1</version>
</dependency> <!-- <dependency>-->
<!-- <groupId>org.eclipse.jdt.core.compiler</groupId>-->
<!-- <artifactId>ecj</artifactId>-->
<!-- <version>4.5</version>-->
<!-- </dependency>-->
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>ecj</artifactId>
<version>3.17.0</version>
</dependency> <dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>4.0.2</version>
<scope>test</scope>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
二、用 IDEA 直接打开
这里删除了一些无用的文件
1.打开项目属性(F4)
把 java 文件夹标记为 Sources,test 文件夹标记为 Tests
2.运行
找到 org.apache.catalina.startup.Bootstrap 运行 main 方法
2.1、ResponseTrailers 找不到,把 home\webapps\examples\WEB-INF\classes\trailers 目录拷贝到 test 目录下
ResponseTrailers.java
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package trailers; import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; /**
* This example writes some trailer fields to the HTTP response.
*/
public class ResponseTrailers extends HttpServlet { private static final long serialVersionUID = 1L;
private static final Supplier<Map<String,String>> TRAILER_FIELD_SUPPLIER =
new TrailerFieldSupplier(); @Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException { resp.setTrailerFields(TRAILER_FIELD_SUPPLIER);
resp.setContentType("text/plain");
resp.setCharacterEncoding("UTF-8"); PrintWriter pw = resp.getWriter(); pw.print("This response should include trailer fields.");
} private static class TrailerFieldSupplier implements Supplier<Map<String,String>> { private static final Map<String,String> trailerFields = new HashMap<>(); static {
trailerFields.put("x-trailer-1", "Trailer value one");
trailerFields.put("x-trailer-2", "Trailer value two");
} @Override
public Map<String, String> get() {
return trailerFields;
}
}
}
2.2、CookieFilter 找不到,把 home\webapps\examples\WEB-INF\classes\util\CookieFilter.java 文件拷贝到 test\util 目录下
CookieFilter.java
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package util; import java.util.Locale;
import java.util.StringTokenizer; /**
* Processes a cookie header and attempts to obfuscate any cookie values that
* represent session IDs from other web applications. Since session cookie names
* are configurable, as are session ID lengths, this filter is not expected to
* be 100% effective.
*
* It is required that the examples web application is removed in security
* conscious environments as documented in the Security How-To. This filter is
* intended to reduce the impact of failing to follow that advice. A failure by
* this filter to obfuscate a session ID or similar value is not a security
* vulnerability. In such instances the vulnerability is the failure to remove
* the examples web application.
*/
public class CookieFilter { private static final String OBFUSCATED = "[obfuscated]"; private CookieFilter() {
// Hide default constructor
} public static String filter(String cookieHeader, String sessionId) { StringBuilder sb = new StringBuilder(cookieHeader.length()); // Cookie name value pairs are ';' separated.
// Session IDs don't use ; in the value so don't worry about quoted
// values that contain ;
StringTokenizer st = new StringTokenizer(cookieHeader, ";"); boolean first = true;
while (st.hasMoreTokens()) {
if (first) {
first = false;
} else {
sb.append(';');
}
sb.append(filterNameValuePair(st.nextToken(), sessionId));
} return sb.toString();
} private static String filterNameValuePair(String input, String sessionId) {
int i = input.indexOf('=');
if (i == -1) {
return input;
}
String name = input.substring(0, i);
String value = input.substring(i + 1, input.length()); return name + "=" + filter(name, value, sessionId);
} public static String filter(String cookieName, String cookieValue, String sessionId) {
if (cookieName.toLowerCase(Locale.ENGLISH).contains("jsessionid") &&
(sessionId == null || !cookieValue.contains(sessionId))) {
cookieValue = OBFUSCATED;
} return cookieValue;
}
}
2.3、conf\server.xml 找不到,设置下 jvm 参数(就是指定之前创建的 home 目录)
-Dcatalina.home=D:\CodeLib\tomcat9\home
2.4、控制台报错:Error configuring application listener of class [listeners.ContextListener]
没找到具体原因,删掉 webapps 下的 examples 文件夹即可
2.5、控制台或网页报错:Servlet.service() for servlet [jsp] in context with path [] threw exception [org.apache.jasper.JasperException: Unable to compile class for JSP] with root cause
编辑 org.apache.catalina.startup.ContextConfig 文件的 configureStart() 方法,添加初始化 JSP 解析器的代码
context.addServletContainerInitializer(new JasperInitializer(), null);
最后访问 http://127.0.0.1:8080/ 就可以看到欢迎页了
Ant方式
解压 tomcat 源码,编辑 build.properties.default 文件,修改 base.path 路径
# ----- Default Base Path for Dependent Packages -----
# Please note this path must be absolute, not relative,
# as it is referenced with different working directory
# contexts by the various build scripts.
base.path=D:/CodeLib/apache-tomcat-9.0.19-src/tomcat-build-libs
下载 Ant,配置环境变量
https://ant.apache.org/bindownload.cgi
# 设置系统环境变量
setx /M ANT_HOME "D:\apache-ant-1.10.5"
setx /M Path "%Path%;%ANT_HOME%\bin"
编译 tomcat,生成 idea 项目
cd D:\CodeLib\apache-tomcat-9.0.19-src
ant
ant ide-intellij
用 idea 打开源码目录,会提示设置变量属性,按照自己设置的目录设置即可,后面运行和 Maven 方式类似
https://gongxufan.github.io/2017/10/20/tomcat-source-debug/
https://emacsist.github.io/tags/tomcat%E6%BA%90%E7%A0%81/
IDEA 导入 Tomcat9 源码的更多相关文章
- IDEA导入tomcat9源码跑起来~
如题,这里记录一下用IDEA导入tomcat9的源码,并跑起来.看了本教程你还是不会的话直接问我. 一.环境安装以及目录搭建 tomcat9源码下载地址:http://mirrors.hust.edu ...
- 探秘Tomcat(一)——Myeclipse中导入Tomcat源码
前言:有的时候自己不知道自己是井底之蛙,这并没有什么可怕的,因为你只要蜷缩在方寸之间的井里,无数次的生活轨迹无非最终归结还是一个圆形:但是可怕的是有一天你不得不从井里跳出来生活,需要重新审视井以外的生 ...
- Eclipse导入Hadoop源码项目及编写Hadoop程序
一 Eclipse导入Hadoop源码项目 基本步骤: 1)在Eclipse新建一个java项目[hadoop-1.2.1] 2)将Hadoop压缩包解压目录src下的core,hdfs,mapred ...
- 关于导入geoserver 源码到Eclipse编译运行
参考http://blog.csdn.net/gisshixisheng/article/details/43016443 和 http://blog.sina.com.cn/s/blog_6e37 ...
- spring源码学习(一):eclipse导入spring源码
前言 对于一门技术,我们最先是了解它(what),然后再熟练的使用它(how)以及何时用它(when),最后肯定要看透它(why).spring作为Java开发人员可以说是最熟悉不过的了,基本每个Ja ...
- eclipse导入Java源码
eclipse导入Java源码 下载源码包(一般jdk都自带了, 我的没有) src.zip eclipse -> window -> preferences -> JAVA -&g ...
- Hadoop1.x目录结构及Eclipse导入Hadoop源码项目
这是解压hadoop后,hadoop-1.2.1目录 各目录结构及说明: Eclipse导入Hadoop源码项目: 注意:如果没有ant的包可以去网上下,不是hadoop里面的. 然后如果通过以上还报 ...
- idea 导入spring 源码注意的问题
问题:idea导入spring 源码的步骤是: 首先从官网下载spring的源码:git clone https://github.com/spring-projects/spring-framewo ...
- 导入android源码中的APP源码到eclipse
导入android源码中的APP源码到eclipse 一般最简单的办法就是创建新的android工程,选择create project from existing source选项,直接导入源码就OK ...
随机推荐
- 解决OracleOraDb10g_home1TNSListener服务无法启动
造成OracleOraDb10g_home1TNSListener服务无法启动可能有三种情况: listener.ora文件配置有错误导致无法启动 相关环境变量没设置好 删除客户端时导致服务端相关注册 ...
- Python安装第三方包(模块/工具)出现链接超时,网速慢,安装不上的问题如何解决
之前我的电脑重新装了系统以后,发现安装完Python后, 使用pip linstall 安装第三方包的时候,网速慢的一匹 有时候只有几百b/s ,而且还动不动就会出现无法安装,链接超时等问题. 今天我 ...
- SQL SERVER 2012 AlwaysOn - 维护篇 03
搭建 AlwaysOn 是件非常繁琐的工作,需要从两方面考虑,操作系统层面和数据库层面,AlwaysOn 非常依赖于操作系统,域控,群集,节点等概念: DBA 不但要熟悉数据库也要熟悉操作系统的一些概 ...
- sql Server 2008 数据库自动备份维护计划
数据库中右键-‘管理’-新建维护计划 创建执行计划,设置备份时间 点击保存 完成 执行后报 ‘’错误5:拒绝访问 ’,时需到文件目录‘属性’→‘安全’设置用户的 ‘写入’ 权限
- Vue.js01:跑马灯效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- cent os 7 与cent os 6 修改主机名称
centos6 需要修改两处:一处是/etc/sysconfig/network,另一处是/etc/hosts,只修改任一处会导致系统启动异常.零时修改用hostname your-name cnet ...
- ARTS打卡第四周
Algorithm 只出现一次的数字 给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次.找出那个只出现了一次的元素. 说明: 你的算法应该具有线性时间复杂度. 你可以不使用 ...
- Redis5.0.4复制
redis的复制很简单,由于资源限制,本例中采用两台虚拟机,每台虚拟机安装两个redis实例,共四个来测试 一.安装redis https://www.cnblogs.com/qq931399960/ ...
- Ubuntu server 16.04的安装 以及配置(服务器版)
1.在电脑上下载最新版本的Ubuntu服务器ISO映像,刻录到CD或创建一个可启动的USB盘. 2.视情况而定,进入到服务器的boot界面,把cd或者usb设置为启动第一项 3.开始安装 1)Ub ...
- 在后台业务管理系统中使用Autofac实现微信接口的处理
在后台业务管理系统中使用Autofac实现微信接口的处理,我们只需要把相关使用到的DLL放到BIN目录里面即可,通过IOC控制反转方式实现对接口的调用.在实现在业务系统里面,我们本身程序可能已经依赖了 ...