IntelliJ IDEA环境导入Tomcat源码

准备

目录结构

  • tomcat-8.5.38 是你想导入的Tomcat源码
  • 新建一个catalina-home目录,把官网下载好(同版本)的已编译好的压缩包解压,把conflibwebapps目录复制到该目录下
  • 新建一个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/maven-v4_0_0.xsd">    
          
          <modelVersion>4.0.0</modelVersion>    
          <groupId>gxf</groupId>    
          <artifactId>apache-tomcat-8</artifactId>    
          <name>tomcat-8.5.38</name>    
          <version>1.0</version>    
          <packaging>pom</packaging>    
          
          <modules>    
              <module>tomcat-8.5.38</module>    
          </modules>    
      </project>
  • Tomcat源码目录同样新建一个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.0</artifactId>    
          <name>Tomcat8.0</name>    
          <version>8.0</version>    
          
          <build>    
              <finalName>Tomcat8.0</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.0.2</version>    
          
                      <configuration>    
                          <encoding>UTF-8</encoding>    
                          <source>1.8</source>    
                          <target>1.8</target>    
                      </configuration>    
                  </plugin>    
              </plugins>    
          </build>    
          
          <dependencies>  
              <dependency>  
                  <groupId>org.easymock</groupId>  
                  <artifactId>easymock</artifactId>  
                  <version>3.5</version>  
                  <scope>test</scope>  
              </dependency>  
        
              <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.2</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.6.1</version>  
              </dependency>    
          </dependencies>    
          
      </project>

更换IDEA Maven源

在IDEA安装目录

IntelliJ IDEA 2018.3.5pluginsmavenlibmaven3conf

目录下的settings.xml文件,打开,在任意一个mirror标签下面添加内容

  <mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>

然后再IDEA File -> Settings,搜索Maven

maven

IDEA 打开项目

打开IDEA,File --> OPEN..,选择目录(不是源码里面的pom)的pom.xml文件,

加载好之后,配置编译环境,在运行按钮旁边的Edit Configurations..

configuration

添加一个Application编译

  • Main Class设置为:org.apache.catalina.startup.Bootstrap
  • VM options设置为:

    -Dcatalina.home=catalina-home
    -Dcatalina.base=catalina-home
    -Djava.io.tmpdir=catalina-home/temp
    -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
    -Djava.util.logging.config.file=catalina-home/conf/logging.properties
  • 选择module为Tomcat8.0(源码所在的module)
  • JRE选择自己的/默认也行

点击运行旁边的小锤子进行构建,有可能测试项目的时候会报错,找到报错的测试文件,删除即可!浏览器访问的时候可能会出现服务器错误,需要添加lib包

addlib

标签: none

添加新评论