tomcat-embeded-core源码编译

≯℡__Kan透↙ 提交于 2020-02-19 14:27:41

使用spring-boot创建web工程时,默认采用embeded tomcat作为容器,实际使用过程中,可能会需要对其中的某些功能做微调,而tomcat又没有给出预留配 ,这时就需要对tomcat-embed-core源码进行编译了,下面说下具体的步骤

创建工程

  1. 在eclipse中创建tomcat-embed-core的maven工程
  2. 通过maven下载一个自己需要编译的tomcat-embed-core版本对应的source包(以8.5.31为例)
  3. 解压tomcat-embed-core对应的source包
  4. 将source包中javax和org两个包copy到刚创建的maven工程的src/main/java目录下
  5. 将source包中的META-INF放到src/main/resources目录下
  6. 编辑pom文件,追加依赖包、编译内容、以及发布的默认maven仓库
    <?xml version="1.0" encoding="UTF-8"?>
    <!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
    -->
    <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.embed</groupId>
    <artifactId>tomcat-embed-core</artifactId>
    <version>8.5.31-me</version>
    <description>Core Tomcat implementation</description>
    <url>http://tomcat.apache.org/</url>
    <licenses>
    <license>
      <name>Apache License, Version 2.0</name>
      <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
      <distribution>repo</distribution>
    </license>
  </licenses>
  <dependencies>
    <dependency>
      <groupId>org.apache.tomcat</groupId>
      <artifactId>tomcat-annotations-api</artifactId>
      <version>8.5.31</version>
      <scope>compile</scope>
    </dependency>
    
    <dependency>
      <groupId>javax.mail</groupId>
      <artifactId>javax.mail-api</artifactId>
      <version>1.5.6</version>
      <scope>provided</scope>
    </dependency>
    
    <dependency>
      <groupId>javax.persistence</groupId>
      <artifactId>javax.persistence-api</artifactId>
      <version>2.2</version>
      <scope>provided</scope>
    </dependency>
    
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
      <scope>provided</scope>
    </dependency>
    
    <dependency>
      <groupId>org.glassfish</groupId>
      <artifactId>javax.ejb</artifactId>
      <version>3.1.1</version>
      <scope>provided</scope>
    </dependency>
    
    
    <dependency>
      <groupId>org.apache.tomcat.embed</groupId>
      <artifactId>tomcat-embed-jasper</artifactId>
      <version>8.5.31</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>
  
  <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                    <include>**/*.xsd</include>
                    <include>**/*.dtd</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>
    
   <distributionManagement>
        <repository>
            <id>my-releases</id>
            <name>my-releases</name>
            <url>http://nexus:8081/repository/my-releases/</url>
        </repository>
        <snapshotRepository>
            <id>my-snapshots</id>
            <name>my-snapshots</name>
            <url>http://nexus:8081/repository/my-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>
</project>

编辑修改需要定制化的类

重新打包

进入工程目录执行,maven deploy,会将打包好的jar包上传到对应的maven仓库中

之后其他工程就可以依赖新打出的jar包
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!