tomcat-embeded-core源碼編譯


使用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包


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM