Tomcat8源码导入idea运行

1)源码下载地址

https://tomcat.apache.org/download-80.cgi#8.5.35

Source Code Distributions

  • tar.gz (pgp, sha512)
  • zip (pgp, sha512)  

2)下载zip包

https://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.57/src/apache-tomcat-8.5.57-src.zip

3)解压到本地

E:\apache-tomcat-8.5.57-src\apache-tomcat-8.5.57-src

4) apache-tomcat-8.5.35-src根目录下创建新建catalina-home目录

5) apache-tomcat-8.5.35-src根目录下创建pom.xml



 
    4.0.0
    org.apache.tomcat
    Tomcat8.5
    Tomcat8.5
    8.5
 
    
        Tomcat8.5
        java
        test
        
            
                java
            
        
        
           
                test
           
        
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                2.3
                
                    UTF-8
                    1.8
                    1.8
                
            
        
    
 
    
        
            junit
            junit
            4.12
            test
        
        
            org.easymock
            easymock
            3.4
        
        
            ant
            ant
            1.7.0
        
        
            wsdl4j
            wsdl4j
            1.6.2
        
        
            javax.xml
            jaxrpc
            1.1
        
        
            org.eclipse.jdt.core.compiler
            ecj
            4.5.1
        
       
    

Tomcat8源码导入idea运行_第1张图片

7) 将apache-tomcat-8.0.53-src目录中的conf和webapps文件夹复制到catalina-home目录中

8) idea导入tomcat项目,就跟导入普通maven项目一样导入即可

Tomcat8源码导入idea运行_第2张图片

导入成功后加载pom.xml依赖

9) 配置idea运行参数

Tomcat8源码导入idea运行_第3张图片

main class:org.apache.catalina.startup.Bootstrap

vm options:

-Dcatalina.home=catalina-home
-Dcatalina.base=catalina-home
-Djava.endorsed.dirs=catalina-home/endorsed
-Djava.io.tmpdir=catalina-home/temp
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.util.logging.config.file=catalina-home/conf/logging.properties
-Dfile.encoding=UTF-8
-Duser.language=en
-Duser.region=US

配置编码和语言是解决乱码问题

02-Sep-2020 22:02:51.659 严重 [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal ç±äºä¹åçé误ï¼Context[/examples]å¯å¨å¤±è´¥
02-Sep-2020 22:02:51.668 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Webåºç¨ç¨åºç®å½[E:\apache-tomcat-8.5.57-src\apache-tomcat-8.5.57-src\catalina-home\webapps\examples]çé¨ç½²å·²å¨[209]毫ç§åå®æ
02-Sep-2020 22:02:51.668 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory æweb åºç¨ç¨åºé¨ç½²å°ç®å½ [E:\apache-tomcat-8.5.57-src\apache-tomcat-8.5.57-src\catalina-home\webapps\host-manager]
02-Sep-2020 22:02:51.774 信息 [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars è³å°æä¸ä¸ªJAR被æ«æç¨äºTLDä½å°æªåå«TLDã 为此记å½å¨å¯ç¨è°è¯æ¥å¿è®°å½ï¼ä»¥è·åå·²æ«æä½æªå¨å¶ä¸­æ¾å°TLDçå®æ´JARå表ã å¨æ«ææé´è·³è¿ä¸éè¦çJARå¯ä»¥ç¼©ç­å¯å¨æ¶é´åJSPç¼è¯æ¶é´ã
02-Sep-2020 22:02:51.783 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Webåºç¨ç¨åºç®å½[E:\apache-tomcat-8.5.57-src\apache-tomcat-8.5.57-src\catalina-home\webapps\host-manager]çé¨ç½²å·²å¨[115]毫ç§åå®æ
02-Sep-2020 22:02:51.783 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory æweb åºç¨ç¨åºé¨ç½²å°ç®å½ [E:\apache-tomcat-8.5.57-src\apache-tomcat-8.5.57-src\catalina-home\webapps\manager]
02-Sep-2020 22:02:51.892 信息 [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars è³å°æä¸ä¸ªJAR被æ«æç¨äºTLDä½å°æªåå«TLDã 为此记å½å¨å¯ç¨è°è¯æ¥å¿è®°å½ï¼ä»¥è·åå·²æ«æä½æªå¨å¶ä¸­æ¾å°TLDçå®æ´JARå表ã å¨æ«ææé´è·³è¿ä¸éè¦çJARå¯ä»¥ç¼©ç­å¯å¨æ¶é´åJSPç¼è¯æ¶é´ã
02-Sep-2020 22:02:51.894 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Webåºç¨ç¨åºç®å½[E:\apache-tomcat-8.5.57-src\apache-tomcat-8.5.57-src\catalina-home\webapps\manager]çé¨ç½²å·²å¨[111]毫ç§åå®æ
02-Sep-2020 22:02:51.894 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory æweb åºç¨ç¨åºé¨ç½²å°ç®å½ [E:\apache-tomcat-8.5.57-src\apache-tomcat-8.5.57-src\catalina-home\webapps\ROOT]
02-Sep-2020 22:02:51.975 信息 [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars è³å°æä¸ä¸ªJAR被æ«æç¨äºTLDä½å°æªåå«TLDã 为此记å½å¨å¯ç¨è°è¯æ¥å¿è®°å½ï¼ä»¥è·åå·²æ«æä½æªå¨å¶ä¸­æ¾å°TLDçå®æ´JARå表ã å¨æ«ææé´è·³è¿ä¸éè¦çJARå¯ä»¥ç¼©ç­å¯å¨æ¶é´åJSPç¼è¯æ¶é´ã
02-Sep-2020 22:02:51.977 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Webåºç¨ç¨åºç®å½[E:\apache-tomcat-8.5.57-src\apache-tomcat-8.5.57-src\catalina-home\webapps\ROOT]çé¨ç½²å·²å¨[83]毫ç§åå®æ
02-Sep-2020 22:02:51.981 信息 [main] org.apache.coyote.AbstractProtocol.start å¼å§åè®®å¤çå¥æ["http-nio-8080"]

10) 编译build

util.TestCookieFilter 测试出现编译错误,将测试用例代码注释即可

11) 运行项目,访问 http://localhost:8080

页面出现错误

org.apache.jasper.JasperException: Unable to compile class for JSP

错误原因:

org.apache.catalina.startup.Bootstrap的时候没有加载org.apache.jasper.servlet.JasperInitializer,从而无法编译JSP

解决方法:

修改类:org.apache.catalina.startup.ContextConfig#configureStart 方法

增加代码:context.addServletContainerInitializer(new JasperInitializer(), null);

protected synchronized void configureStart() {
        // Called from StandardContext.start()

        if (log.isDebugEnabled()) {
            log.debug(sm.getString("contextConfig.start"));
        }

        if (log.isDebugEnabled()) {
            log.debug(sm.getString("contextConfig.xmlSettings",
                    context.getName(),
                    Boolean.valueOf(context.getXmlValidation()),
                    Boolean.valueOf(context.getXmlNamespaceAware())));
        }

        webConfig();

        /**
         * 支持jsp 
         */
        context.addServletContainerInitializer(new JasperInitializer(), null);

        if (!context.getIgnoreAnnotations()) {
            applicationAnnotationsConfig();
        }

12)再次运行项目

修改代码:apache-tomcat-8.5.57-src\catalina-home\webapps\ROOT\index.jsp

 

Tomcat8源码导入idea运行_第4张图片

 

你可能感兴趣的:(tomcat,tomcat源码,tomcat导入idea)