springboot maven打包分離 lib resource 配置資源文件
注:
使用maven命令打包,不一樣的IDE能夠同樣的操做
在pom文件中,設置兩個屬性web
<properties> <output.dependence.file.path>lib/</output.dependence.file.path> <output.resource.file.path>resource/</output.resource.file.path> </properties> 設置build節點。這樣在pom文件目錄執行mvn clean package命令,就能在target文件夾輸出打包結果了: 依賴的jar會輸出到output.dependence.file.path指定的文件夾,配置文件輸出到output.resource.file.path 指定的文件夾
經過pom文件使用mvn package 一建打包spring
lib:放第三方JARapache
resources:存配置文件springboot
<plugins> <!-- 打JAR包,不包含依賴文件;顯式剔除配置文件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <!--不打包資源文件,剔除配置文件--> <excludes> <exclude>*.**</exclude> <exclude>*/*.xml</exclude> <exclude>*.properties</exclude> <exclude>*.yml</exclude> <exclude>*/*.properties</exclude> <exclude>*/*.yml</exclude> </excludes> <archive> <manifest> <!--將classpath添加到依賴描述 --> <addClasspath>true</addClasspath> <!--MANIFEST.MF 中 Class-Path 加入前綴--> <!--lib文件夾內容,須要 maven-dependency-plugin插件補充--> <classpathPrefix>lib/</classpathPrefix> <!--jar包不包含惟一版本標識--> <useUniqueVersions>false</useUniqueVersions> <!--指定入口類--> <mainClass>site.yuyanjia.template.Application</mainClass> </manifest> <manifestEntries> <!--MANIFEST.MF 中 Class-Path 加入資源文件目錄,加入自定義路徑,多個路徑用空格隔開--> <!--此處resources文件夾的內容,須要maven-resources-plugin插件補充上--> <Class-Path>./resources/</Class-Path> </manifestEntries> </archive> <outputDirectory>${project.build.directory}</outputDirectory> </configuration> </plugin> <!--拷貝依賴 copy-dependencies--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory> ${project.build.directory}/lib/ </outputDirectory> </configuration> </execution> </executions> </plugin> <!--拷貝資源文件 copy-resources--> <plugin> <artifactId>maven-resources-plugin</artifactId> <executions> <execution> <id>copy-resources</id> <phase>package</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <resources> <resource> <directory>src/main/resources</directory> <includes> <include>*.properties</include> <include>*.yml</include> <include>*/*.properties</include> <include>*/*.properties</include> </includes> </resource> </resources> <outputDirectory>${project.build.directory}/resources</outputDirectory> </configuration> </execution> </executions> </plugin> <!--spring boot repackage,依賴 maven-jar-plugin 打包的jar包 從新打包成 spring boot 的jar包--> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <!--重寫包含依賴,包含不存在的依賴,jar裏沒有pom裏的依賴--> <includes> <include> <groupId>non-exists</groupId> <artifactId>non-exists</artifactId> </include> </includes> <layout>ZIP</layout> <!--使用外部配置文件,jar包裏沒有資源文件--> <addResources>true</addResources> <outputDirectory>${project.build.directory}</outputDirectory> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> <configuration> <!--配置jar包特殊標識 配置後,保留原文件,生成新文件 *-run.jar --> <!--配置jar包特殊標識 不配置,原文件命名爲 *.jar.original,生成新文件 *.jar --> <!--<classifier>run</classifier>--> </configuration> </execution> </executions> </plugin> <!--maven打包時,跳過測試--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skip>true</skip> </configuration> </plugin> </plugins>