Tomcat源码启动部署配置
2、idea新建空的项目
3、配置项目jdk,maven的settings仓库地址。
4、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>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> <!-- https://mvnrepository.com/artifact/javax.xml/jaxrpc --> <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>
5、新建home文件夹,将conf,webapps目录移动至home文件夹中
6、导入源码src项目。下载依赖。
7、新建启动类,指定Main.class :org.apache.catalina.startup.Bootstrap.
VM options -Dcatalina.home=D:\gitCodes\tomcat8.5-source-learning\apache-tomcat-8.5.70-src\home -Dcatalina.base=D:\gitCodes\tomcat8.5-source-learning\apache-tomcat-8.5.70-src\home
8、解决启动控制台乱码
修改类:org/apache/tomcat/util/res/StringManager.java public String getString(final String key, final Object... args) { String value = getString(key); if (value == null) { value = key; } // 控制台打印乱码 try { value = new String(value.getBytes("ISO-8859-1"),"UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } MessageFormat mf = new MessageFormat(value); mf.setLocale(locale); return mf.format(args, new StringBuffer(), null).toString(); } 修改类:org/apache/jasper/compiler/Localizer.java public static String getMessage(String errCode) { String errMsg = errCode; try { if (bundle != null) { errMsg = bundle.getString(errCode); } } catch (MissingResourceException e) { } // 控制台打印乱码 try { errMsg = new String(errMsg.getBytes("ISO-8859-1"),"UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return errMsg; }
9、再次启动,页面报错jsp无法解析
修改类:org/apache/catalina/startup/ContextConfig.java 785行代码 webConfig(); // 解决 无法编译JSP,启动报错 500的问题 context.addServletContainerInitializer(new JasperInitializer(),null);

浙公网安备 33010602011771号