SpringBoot服務(wù)拆包打包的詳細(xì)實(shí)現(xiàn)過(guò)程
前言
涵蓋技術(shù)內(nèi)容:Java后端、大數(shù)據(jù)、算法、分布式微服務(wù)、中間件、前端、運(yùn)維等。
原始打包
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<includeSystemScope>true</includeSystemScope>
<!-- 指定主類 -->
<mainClass>com.dtstack.knowledge.ai.server.KnowLedgeServerApplication</mainClass>
</configuration>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
<configuration>
<attach>true</attach>
</configuration>
</plugin>
</plugins>
</build>
編譯打包之后為:

拆包實(shí)現(xiàn)
引入pom.xml依賴 & 新建assembly.xml

關(guān)鍵點(diǎn)為:
- maven-shade-plugin中的
<include>com.changlu:knowledge-*</include>,表示對(duì)應(yīng)的com.changlu 指的是groupId,后綴knowledge-*指的是artifactId。 - maven-jar-plugin中的指定啟動(dòng)器類:
<mainClass>com.dtstack.knowledge.ai.server.KnowLedgeServerApplication</mainClass> - maven-antrun-plugin中指定了拷貝路徑。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
</dependency>
</dependencies>
<configuration>
<keepDependenciesWithProvidedScope>false</keepDependenciesWithProvidedScope>
<createDependencyReducedPom>false</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>com.changlu:knowledge-*</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<!-- 后續(xù)打包可以識(shí)別到${git.branch} -->
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>2.2.6</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<dateFormat>yyyy.MM.dd HH:mm:ss</dateFormat>
<prefix>git</prefix>
<verbose>true</verbose>
<!-- 是否單獨(dú)生成properties文件 -->
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<!-- 沒(méi)有 .git 目錄時(shí)則構(gòu)建失敗,false:繼續(xù)構(gòu)建-->
<failOnNoGitDirectory>false</failOnNoGitDirectory>
<!-- 生成文件路徑-->
<generateGitPropertiesFilename>${project.basedir}/src/main/resources/git.properties</generateGitPropertiesFilename>
<gitDescribe>
<always>false</always>
<dirty>-dirty</dirty>
<forceLongFormat>false</forceLongFormat>
</gitDescribe>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifestEntries>
<Class-Path>.</Class-Path>
</manifestEntries>
<manifest>
<!-- 工程主入口 -->
<mainClass>com.dtstack.knowledge.ai.server.KnowLedgeServerApplication</mainClass>
<addClasspath>true</addClasspath>
</manifest>
</archive>
<excludes>
<exclude>application.properties</exclude>
<exclude>application.yaml</exclude>
<exclude>logback.xml</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<copy file="${basedir}/target/${project.name}-${project.version}.jar"
tofile="${basedir}/target/dtstack-platform/dtstack-platform/dtstack/${project.name}-${git.branch}.jar"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<!-- assembly 插件打包-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>data-module</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
<outputDirectory>target</outputDirectory>
<!-- 打包路徑名稱-->
<finalName>dtstack-platform</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
assembly.xml:
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>dt_public_service</id>
<includeBaseDirectory>true</includeBaseDirectory>
<!-- 輸出格式為linux下的dir格式格式-->
<formats>
<format>dir</format>
</formats>
<dependencySets>
<!-- 依賴所屬jar包目錄存儲(chǔ)-->
<dependencySet>
<useProjectArtifact>true</useProjectArtifact>
<!-- 改動(dòng)解釋:需要提出當(dāng)前對(duì)應(yīng)的源碼包的打包,目的是將對(duì)應(yīng)的依賴拆分出來(lái)
com.changlu 指的是groupId,后綴knowledge-*指的是artifactId
-->
<excludes>
<exclude>com.changlu:knowledge-*</exclude>
</excludes>
<outputDirectory>lib</outputDirectory>
<outputFileNameMapping>${artifact.groupId}-${artifact.artifactId}.${artifact.extension}</outputFileNameMapping>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
執(zhí)行打包命令與測(cè)試

輸出的打包后文件目錄為,實(shí)現(xiàn)了拆包效果:

執(zhí)行的命令為:
本機(jī):
/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home/bin/java -cp “/Users/edy/changlu_workspace/daishuyun/材料/2025/2025.6.1黑客馬拉松/code/knowledge-ai-chat/knowledge-ai-server/target/dtstack-platform/dtstack-platform/dtstack/:/Users/edy/changlu_workspace/daishuyun/材料/2025/2025.6.1黑客馬拉松/code/knowledge-ai-chat/knowledge-ai-server/target/dtstack-platform/dtstack-platform/lib/” com.dtstack.knowledge.ai.server.KnowLedgeServerApplication
服務(wù)器:
# -cp 指定目錄加載,這里指定兩個(gè)位置: # /opt/tools/ai-chat/knowledge-server/lib/*、 /opt/tools/ai-chat/jdk/jdk-17.0.10+7/bin/java 、/opt/tools/ai-chat/knowledge-server/dtstack/* -cp /opt/tools/ai-chat/knowledge-server/lib/*:/opt/tools/ai-chat/knowledge-server/dtstack/* com.dtstack.knowledge.ai.server.KnowLedgeServerApplication
說(shuō)明:后續(xù)真實(shí)項(xiàng)目的執(zhí)行,后使用shell腳本形式來(lái)完成啟動(dòng)和關(guān)閉。
以上就是SpringBoot服務(wù)拆包打包的詳細(xì)實(shí)現(xiàn)過(guò)程的詳細(xì)內(nèi)容,更多關(guān)于SpringBoot服務(wù)拆包打包的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
spring定時(shí)器定時(shí)任務(wù)到時(shí)間未執(zhí)行問(wèn)題的解決
這篇文章主要介紹了spring定時(shí)器定時(shí)任務(wù)到時(shí)間未執(zhí)行問(wèn)題的解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-11-11
Java利用Spire.Doc for Java實(shí)現(xiàn)在Word文檔中插入圖片
本文將深入探討如何利用 Spire.Doc for Java 這一強(qiáng)大庫(kù),在 Java 程序中高效、靈活地實(shí)現(xiàn) Word 文檔的圖片插入功能,包括不同環(huán)繞方式和指定位置的插入,有需要的小伙伴可以了解下2025-10-10
在SpringBoot項(xiàng)目中如何實(shí)現(xiàn)線程池的動(dòng)態(tài)監(jiān)控
Spring Boot因其簡(jiǎn)便、高效的特點(diǎn)廣受開發(fā)者喜愛,在復(fù)雜的業(yè)務(wù)場(chǎng)景下,如何確保Spring Boot應(yīng)用的高性能和穩(wěn)定性成為了一個(gè)關(guān)鍵問(wèn)題,其中,線程池的管理策略直接影響到系統(tǒng)的吞吐量和資源利用效率,本文將重點(diǎn)探討在Spring Boot項(xiàng)目中,如何實(shí)現(xiàn)線程池的動(dòng)態(tài)監(jiān)控2023-10-10
基于SpringBoot+Vue實(shí)現(xiàn)DeepSeek對(duì)話效果的詳細(xì)步驟
本文詳細(xì)介紹了使用SpringBoot和Vue構(gòu)建對(duì)話系統(tǒng),包含API設(shè)計(jì)、聊天界面開發(fā)、前后端集成及WebSocket優(yōu)化,實(shí)現(xiàn)類似DeepSeek的交互效果,需要的朋友可以參考下2025-07-07
maven多個(gè)倉(cāng)庫(kù)查詢的優(yōu)先級(jí)順序案例講解
這篇文章主要介紹了maven多個(gè)倉(cāng)庫(kù)查詢的優(yōu)先級(jí)順序,考慮到我們常用的配置文件是conf/settings.xml和工程里面的pom.xml文件,我們針對(duì)這兩個(gè)文件的結(jié)合來(lái)分析倉(cāng)庫(kù)的使用順序,需要的朋友可以參考下2023-04-04
一篇文章教你學(xué)會(huì)用Java程序操作文件及避坑指南
文件的讀取與寫入操作是Java開發(fā)中的基礎(chǔ)且重要的一環(huán),從傳統(tǒng)的字節(jié)流與字符流到高級(jí)的緩沖流與NIO,每種技術(shù)都有其適用場(chǎng)景和優(yōu)缺點(diǎn),這篇文章主要介紹了用Java程序操作文件及避坑指南的相關(guān)資料,需要的朋友可以參考下2026-06-06
MyBatis?Plus如何實(shí)現(xiàn)獲取自動(dòng)生成主鍵值
這篇文章主要介紹了MyBatis?Plus如何實(shí)現(xiàn)獲取自動(dòng)生成主鍵值問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-09-09
學(xué)習(xí)C語(yǔ)言對(duì)后期java有幫助嗎
在本篇文章里小編給大家整理的是一篇關(guān)于學(xué)習(xí)C語(yǔ)言對(duì)后期java有幫助嗎的基礎(chǔ)文章,有興趣的朋友們可以參考下。2020-11-11

