@TOC
tomcat源码分析(1)-环境搭建
不知道最近为啥总是不再状态,没有看过太大的工程,也不做简介了,顺便当下笔记来使用吧
- 源码下载地址
- 修改目录文件,配置webapss目录,配置pom
- 配置jsp解析、解决版本错误
源码下载地址及版本
https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.16/src/apache-tomcat-9.0.16-src.zip
修改目录文件,配置webapps目录
将apache-tomcat-9.0.16-src下新建home文件,将conf与webapps目录移动至home文件中
创建maven 项目配置文件
在apache-tomcat-9.0.16-src 新建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>Tomcat9.0</artifactId>
<name>Tomcat9.0</name>
<version>9.0</version>
<build>
<finalName>Tomcat9.0</finalName>
<sourceDirectory>java</sourceDirectory>
<resources>
<resource>
<directory>java</directory>
</resource>
</resources>
<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>ant</groupId>
<artifactId>ant</artifactId>
<version>1.7.0</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.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>4.5.1</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>javax.servlet</groupId>-->
<!-- <artifactId>javax.servlet-api</artifactId>-->
<!-- <version>3.0.1</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>javax.servlet.jsp</groupId>-->
<!-- <artifactId>jsp-api</artifactId>-->
<!-- <version>2.1</version>-->
<!-- </dependency>-->
</dependencies>
</project>
配置jvm commad
使用IDEA打开此项目,添加build,application,jvm command
main class
org.apache.catalina.startup.Bootstrap
vm options
-Dcatalina.home=D:/code/java/apache-tomcat-9.0.16-src/apache-tomcat-9.0.16-src/home -Dcatalina.base=D:/code/java/apache-tomcat-9.0.16-src/apache-tomcat-9.0.16-src/home -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=D:/code/java/apache-tomcat-9.0.16-src/apache-tomcat-9.0.16-src/home/conf/logging.properties
异常问题解决
本机使用jdk 8uXXX
将所有错误修改1_8
输出台中文乱码
修改org.apache.tomcat.util.res.StringManager类中的getString函数;
if (bundle != null) {
str = bundle.getString(key);
}
改为
if (bundle != null) {
str = new String(bundle.getString(key).getBytes(“ISO-8859-1”), “UTF-8”);
}
jsp解析在org,apache.cayalina.startup.contextconfig.java中webconfig()下添加
context.addServletContainerInitializer(new JasperInitializer(), null);