网上很多文章都推荐使用Ant下载编译,但本地实践中屡屡失败,无法下载。

后来参考 https://blog.csdn.net/xiongyouqiang/article/details/78941077 总算把调试环境搭建完成。

以下文章几乎完全copy上述网址,但稍作延展。

下载源码

官网直接下载源码

http://tomcat.apache.org/download-70.cgi

源码导入到Eclipse中

第1步:Eclipse中新建一个Java Project,例如名称可以是Tomcat-Src

第2步:在工程上点击右键=>Import=>General=>File System,点击Next按钮。

第3步:点击Browser按钮,找到tomcat源码解压路径,勾选java、test、conf和webapps目录(注意不需要勾选examples目录),点击Finish按钮。

第4步:在java和test目录上点击右键=>Build Path=>Use As Source Folder將这两个目录设为源码目录。同时可以删除工程中原有的src目录了。

第5步:解决导入后工程中出现的编译错误,一般都是由于缺少某些jar导致

主要导入以下几个jar饱

ant.jar

ecj-4.4.2.jar

jaxrpc.jar

wsdl4j-1.5.2.jar

easymock-3.5.1.jar

在工程中新建一个lib目录,將这些jar包放到该目录下,同时添加到build path中。

apache tomcat采用junit作为单元测试工具,我们需要为工程添加Junit支持,在工程上点击右键=>Properties=>Java build path。

点击Add Library按钮,选择Junit4即可。

此时test包中的TestCookieFilter类会报CookieFilter编译异常,这是因为缺少CookieFilter这个类导致,经过一番查找总算找到了CookieFilter源码如下所示:

/*

* 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;

}

}

此时仍有部分error,但不影响调试

设置Debug Configuration,设定程序入口,开始调试!

————————————————
原文链接:https://blog.csdn.net/xiongyouqiang/article/details/78941077

[Tomcat源码分析] Eclipse中搭建Apache Tomcat源码调试环境的更多相关文章

  1. Eclipse中搭建Apache Tomcat7源码调试环境

    第一步:获取Apache Tomcat7源码,读者可以从Apache 官方网站获取,官方下载地址: http://tomcat.apache.org/download-70.cgi 注意选择Sourc ...

  2. Tomcat源码分析----eclipse中搭建源码环境

    前提:JDK,至少1.7,ant,要设置ANT_HOME环境变量,需要再classpath中增加ant的lib目录,在path变量中增加ant的bin目录 1.官网下载tomcat源码包:apache ...

  3. mac系统中搭建apache+mysql+php的开发环境,安装mysql后,登录报错:mac ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

    php新手在mac系统中搭建apache+mysql+php的开发环境(按照这篇博客来操作的:http://my.oschina.net/joanfen/blog/171109?fromerr=xvC ...

  4. 装载 | Eclipse中搭建最新版本的Android开发环境

    文章目录 准备工作 下载文件 下载JDK并配置系统变量环境 下载安装Eclipse 下载Android SDK 下载ADT插件 使用下载好的软件搭建Android开发环境 安装Android的SDK ...

  5. Tomcat源码分析二:先看看Tomcat的整体架构

    Tomcat源码分析二:先看看Tomcat的整体架构 Tomcat架构图 我们先来看一张比较经典的Tomcat架构图: 从这张图中,我们可以看出Tomcat中含有Server.Service.Conn ...

  6. 将Android源码导入eclipse中的方法以及编译Android源码指定模块

    本文博客地址:http://blog.csdn.net/qq1084283172/article/details/53365659 将android源码导入eclipse.androidstudio. ...

  7. 在Eclipse中关联Android API源码

    在Eclipse中快速关联API源码,便于查看类以及方法.方法如下: 1. 在对应的项目文件右键——>properties——>java build path——>libraries ...

  8. 在eclipse中建立子级源码文件夹

    在eclipse中建立子级源码文件夹 右键点击项目 ---->new ---->source folder--->输入 src/main  --->勾选update exclu ...

  9. OSGI企业应用开发(二)Eclipse中搭建Felix运行环境

    上篇文章介绍了什么是OSGI以及使用OSGI构建应用的优点,接着介绍了两款常用的OSGI实现,分别为Apache Felix和Equinox,接下来开始介绍如何在Eclipse中使用Apache Fe ...

随机推荐

  1. xml解析-jaxp修改结点

    jaxp修改结点 / 修改第一个p1下面的sex内容是nan * 1.创建解析器工厂 * 2.根据解析器工厂创建解析器 * 3.解析xml返回document * 4.得到sex item方法 * 5 ...

  2. 2019年上半年收集到的人工智能Python编程干货文章

    2019年上半年收集到的人工智能Python编程干货文章 一文了解Python深拷贝与浅拷贝问题 Python广度优先查找和深度优先查找(内附python教程分享) Python基础之函数2 (参数的 ...

  3. Android框架Volley之:利用Imageloader和NetWorkImageView加载图片

    首先我们在项目中导入这个框架: implementation 'com.mcxiaoke.volley:library:1.0.19' 在AndroidManifest文件当中添加网络权限: < ...

  4. 简易用户管理系统-前端实现(表单&提交请求&button$基础)

    laravel框架编写简易用户管理系统,前端Layui框架. 1.动态生成列表项 实现效果 PHP后台传入用户对象($users). 前端页面接收数据传入table. 逻辑就是在生成表格时,遍历传来的 ...

  5. ElasticSearch安装及运行的坑

    一.确认centos系统是为64位的,x86的不可以安装 1. 下载elasticsearch包 2. 用 tar -zxvf 解压包 3. 增加一个elk用户,elasticsearch7不可用ro ...

  6. protocol buffers 使用方法

    protocol buffers 使用方法 为什么使用 Protocol Buffers 我们接下来要使用的例子是一个非常简单的"地址簿"应用程序,它能从文件中读取联系人详细信息. ...

  7. [MySQL] 解决Error 1698: Access denied for user 'root'@'localhost'

    当程序中使用root账号连接mysql时报以下错误,但是使用命令行是可以正常连接的,那么就查询下mysql数据库的user表,查看下当前用户的密码加密方式,看看是不是unix_socketMariaD ...

  8. requests---requests发送xml数据类型

    上一篇简单的介绍了post常见的4种数据类型,今天我们一起学习通过requests发送xml数据类型 xml数据类型 下方数据为xml数据,我们就通过这段数据学习如果通过requests发送xml数据 ...

  9. C++ 基础语法 快速复习笔记---面对对象编程(2)

    1.C++面对对象编程: a.定义: 类定义是以关键字 class 开头,后跟类的名称.类的主体是包含在一对花括号中.类定义后必须跟着一个分号或一个声明列表. 关键字 public 确定了类成员的访问 ...

  10. 12. final修饰符

    一.final修饰符概述 1. final可以修饰类.变量和方法 2. final修饰的类.变量和方法不可改变 3. 不允许为final变量重新赋值,子类不允许覆盖父类的final方法,final类不 ...