1. 程式人生 > >SpringBoot將所有依賴(包括本地jar包)打包到專案

SpringBoot將所有依賴(包括本地jar包)打包到專案

Maven 新增本地依賴包
在專案根目錄新增lib資料夾,存放不在maven倉庫中存在的jar包
如下兩個推送包,(名字可以自定義)

//華為推送服務端jar包
HwPush_SDK_Server_0_3_12.jar

//小米推送服務端jar包
MiPush_SDK_Server_2_2_18.jar

在pom.xml中新增依賴
<dependency>
    <groupId>com.xiaomi</groupId>
    <artifactId>MiPush_SDK_Server_2_2_18</artifactId>
    <version>2.2.18</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/MiPush_SDK_Server_2_2_18.jar  </systemPath>
</dependency>

<!-- 華為推送 -->
<dependency>
    <groupId>com.huawei.hms</groupId>
    <artifactId>HwPush_SDK_Server_0_3_12</artifactId>
    <version>0.3.12</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/HwPush_SDK_Server_0_3_12.jar</systemPath>
</dependency>

在SpriingBoot中將本地jar包打包到專案的jar包裡,需要build中新增如下內容:
<build>  

    <plugins>  

        <plugin>  
            <groupId>org.springframework.boot</groupId>  
            <artifactId>spring-boot-maven-plugin</artifactId>  
            <configuration>  
                <!-- 指定SpringBoot程式的main函式入口類 -->
                <mainClass>com.redsoft.epip.EPIPApplication</mainClass>  
            </configuration>  

            <executions>  
                <execution>  
                    <goals>  
                        <goal>repackage</goal>  
                    </goals>  
                </execution> 
            </executions>  
        </plugin>  

        <plugin>  
            <artifactId>maven-compiler-plugin</artifactId>  
            <configuration>  
                <source>1.8</source>  
                <target>1.8</target>  
                <encoding>UTF-8</encoding>  
                <compilerArguments>  
                    <!-- 打包本地jar包 -->
                    <extdirs>${project.basedir}/lib</extdirs>  
                </compilerArguments>  
            </configuration>  
        </plugin>  
    </plugins>  

    <!-- 打包所有jar包 -->
    <resources>  
        <resource>  
            <directory>lib</directory>  
            <targetPath>BOOT-INF/lib/</targetPath>  
            <includes>  
                <include>**/*.jar</include>  
            </includes>  
        </resource>  

    <!-- 某些情況下,打包後執行不起來需要開啟註釋 -->
    <!-- <resource>
        <directory>src/main/resources</directory>
        <targetPath>BOOT-INF/classes/</targetPath>
    </resource> -->
    </resources>  

</build>  

執行package命令後即可將本地jar包打進去
--------------------- 
作者:飛鳥的軌跡 
來源:CSDN 
原文:https://blog.csdn.net/u010004082/article/details/79351227 
版權宣告:本文為博主原創文章,轉載請附上博文連結!