Spring Boot 打包分离依赖 JAR 和配置文件

环境:STS
框架:SpringBoot

一、Jar包启动

分离 JAR 包和配置文件,使用 Maven 插件:

<plugins>
    
    <plugin>
        <groupId>org.apache.maven.pluginsgroupId>
        <artifactId>maven-jar-pluginartifactId>
        <configuration>
            
            <excludes>
                <exclude>*.**exclude>
                <exclude>*/*.xmlexclude>
            excludes>
            <archive>
                <manifest>
                    <addClasspath>trueaddClasspath>
                    
                    <classpathPrefix>lib/classpathPrefix>
                    
                    <useUniqueVersions>falseuseUniqueVersions>
                    
                    <mainClass>site.yuyanjia.template.ApplicationmainClass>
                manifest>
                <manifestEntries>
                    
                    <Class-Path>./resources/Class-Path>
                manifestEntries>
            archive>
            <outputDirectory>${project.build.directory}outputDirectory>
        configuration>
    plugin>

    
    <plugin>
        <groupId>org.apache.maven.pluginsgroupId>
        <artifactId>maven-dependency-pluginartifactId>
        <executions>
            <execution>
                <id>copy-dependenciesid>
                <phase>packagephase>
                <goals>
                    <goal>copy-dependenciesgoal>
                goals>
                <configuration>
                    <outputDirectory>${project.build.directory}/lib/outputDirectory>
                configuration>
            execution>
        executions>
    plugin>

    
    <plugin>
        <artifactId>maven-resources-pluginartifactId>
        <executions>
            <execution> 
                <id>copy-resourcesid>
                <phase>packagephase>
                <goals>
                    <goal>copy-resourcesgoal>
                goals>
                <configuration>
                    <resources>
                        <resource>
                            <directory>src/main/resourcesdirectory>
                            <includes>
                                
                            includes>
                        resource>
                    resources>
                    <outputDirectory>${project.build.directory}/resourcesoutputDirectory>
                configuration>
            execution>
        executions>
    plugin>

    
    <plugin>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-maven-pluginartifactId>
        <configuration>
            
            <includes>
                <include>
                    <groupId>nullgroupId>
                    <artifactId>nullartifactId>
                include>
            includes>
            <layout>ZIPlayout>
            
            <addResources>trueaddResources>
            <outputDirectory>${project.build.directory}/resourcesoutputDirectory>
        configuration>
        <executions>
            <execution>
                <goals>
                    <goal>repackagegoal>
                goals>
                <configuration>
                    
                    
                    
                configuration>
            execution>
        executions>
    plugin>
plugins>

Maven打包指令:mvn package

参考地址:https://www.jianshu.com/p/dbdece9062b3

你可能感兴趣的:(SpringBoot,Spring,Boot,打包分离依赖,JAR,和配置文件)