# tomcat9 **Repository Path**: wanglhup/tomcat9 ## Basic Information - **Project Name**: tomcat9 - **Description**: 学习tomcat9源码 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-06-04 - **Last Updated**: 2020-12-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 欢迎看到老王学习Tomcat ## 构建源码 ### 下载官方源码 进入[TOMCAT官网](https://tomcat.apache.org/)下载TOMCAT 9源码 注意要下载`Source Code Distributions`下的压缩包才是源码 这里我下载到的版本是`apache-tomcat-9.0.35-src.zip` ### pom.xml 选择的依赖版本很重要,不然运行不起来 ```xml 4.0.0 com.wanglh Tomcat9.0 Tomcat9 9.0 Tomcat9 java java org.apache.maven.plugins maven-compiler-plugin 2.3 UTF-8 1.8 1.8 org.apache.ant ant 1.9.5 org.apache.ant ant-apache-log4j 1.9.5 org.apache.ant ant-commons-logging 1.9.5 javax.xml.rpc javax.xml.rpc-api 1.1 wsdl4j wsdl4j 1.6.2 org.eclipse.jdt.core.compiler ecj 4.4 ``` ### 去掉无用报错代码 有些代码版本正确也没用,点运行会编译错误,将它注释掉就好(有两段) ```java // JDTCompiler.java // Version format changed from Java 9 onwards. // Support old format that was used in EA implementation as well // 屏蔽以下几个不能识别的版本 // } else if(opt.equals("9") || opt.equals("1.9")) { // settings.put(CompilerOptions.OPTION_TargetPlatform, // CompilerOptions.VERSION_9); // settings.put(CompilerOptions.OPTION_Compliance, // CompilerOptions.VERSION_9); // } else if(opt.equals("10")) { // settings.put(CompilerOptions.OPTION_TargetPlatform, // CompilerOptions.VERSION_10); // settings.put(CompilerOptions.OPTION_Compliance, // CompilerOptions.VERSION_10); // } else if(opt.equals("11")) { // settings.put(CompilerOptions.OPTION_TargetPlatform, // CompilerOptions.VERSION_11); // settings.put(CompilerOptions.OPTION_Compliance, // CompilerOptions.VERSION_11); // } else if(opt.equals("12")) { // settings.put(CompilerOptions.OPTION_TargetPlatform, // CompilerOptions.VERSION_12); // settings.put(CompilerOptions.OPTION_Compliance, // CompilerOptions.VERSION_12); ``` ### 运行路径 在工程中新建 home(或者其他路径),将conf/ webapps/ 拷贝进去 (工程中已经拷贝) 运行后,会在这个目录下生成`logs`、`work`文件夹。 ### JAVA环境 **需要JDK 1.8的环境** ### 启动类 `org.apache.catalina.startup.Bootstrap`作为启动类 ### jvm 运行时参数 启动时需要指定catalina的一些运行时参数,具体路径需要自己修改 ```text -Dcatalina.home=F:\tomcat9Src\apache-tomcat-9.0.35-src\home -Dcatalina.base=F:\tomcat9Src\apache-tomcat-9.0.35-src\home -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=F:\tomcat9Src\apache-tomcat-9.0.35-src\conf\logging.properties -Dfile.encoding=UTF8 -Dsun.jnu.encoding=UTF8 ``` ## 运行 点击运行后访问本地8080端口: `http://localhost:8080/` 就可以看到TOMCAT界面了。 ## 结语 欢迎直接fork[本工程](https://gitee.com/wanglh23469/tomcat9),已经完成删除无用代码,并且有添加中文注释、中文日志。