Spring Boot 打包分离依赖 JAR 和配置文件
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <properties> 2 <java.version>1.8</java.version> 3 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 4 <!--自定义路径--> 5 <directory>c:/makeCode/${name}/</directory> 6 <!--跳过检查--> 7 <skipCheck>false</skipCheck> 8 <!--跳过测试代码--> 9 <skipTests>true</skipTests> 10 <skipDocs>true</skipDocs> 11 </properties> 12 13 <dependencies> 14 ……………… 15 </dependencies> 16 17 <build> 18 <plugins> 19 <!--clean其它路径下的文件--> 20 <plugin> 21 <groupId>org.apache.maven.plugins</groupId> 22 <artifactId>maven-clean-plugin</artifactId> 23 <configuration> 24 <!--除默认目录外,要删除的文件列表--> 25 <filesets> 26 <fileset> 27 <directory>${directory}</directory> 28 </fileset> 29 </filesets> 30 </configuration> 31 </plugin> 32 33 <!--打包jar--> 34 <plugin> 35 <groupId>org.apache.maven.plugins</groupId> 36 <artifactId>maven-jar-plugin</artifactId> 37 <configuration> 38 <!--不打包资源文件--> 39 <excludes> 40 <exclude>*.**</exclude> 41 </excludes> 42 <archive> 43 <manifest> 44 <addClasspath>true</addClasspath> 45 <!--MANIFEST.MF 中 Class-Path 加入前缀--> 46 <classpathPrefix>lib/</classpathPrefix> 47 <!--jar包不包含唯一版本标识--> 48 <useUniqueVersions>false</useUniqueVersions> 49 <!--指定入口类--> 50 <mainClass>com.madaima.ipmanagement.IpManagementApplication</mainClass> 51 </manifest> 52 </archive> 53 <outputDirectory>${directory}</outputDirectory> 54 </configuration> 55 </plugin> 56 57 <!--拷贝依赖 copy-dependencies--> 58 <plugin> 59 <groupId>org.apache.maven.plugins</groupId> 60 <artifactId>maven-dependency-plugin</artifactId> 61 <executions> 62 <execution> 63 <id>copy-dependencies</id> 64 <phase>package</phase> 65 <goals> 66 <goal>copy-dependencies</goal> 67 </goals> 68 <configuration> 69 <outputDirectory> 70 ${directory}/lib/ 71 </outputDirectory> 72 </configuration> 73 </execution> 74 </executions> 75 </plugin> 76 77 <!--拷贝资源文件 copy-resources--> 78 <plugin> 79 <artifactId>maven-resources-plugin</artifactId> 80 <executions> 81 <execution> 82 <id>copy-resources</id> 83 <phase>package</phase> 84 <goals> 85 <goal>copy-resources</goal> 86 </goals> 87 <configuration> 88 <resources> 89 <resource> 90 <directory>src/main/resources</directory> 91 <!-- 指定参与构建的resoures--> 92 <includes> 93 <include>*.**</include> 94 </includes> 95 </resource> 96 </resources> 97 <outputDirectory>${directory}/config</outputDirectory> 98 </configuration> 99 </execution> 100 </executions> 101 </plugin> 102 </plugins> 103 </build>
这样配置后,打包出来的文件就在,c:/makeCode/pom文件中的name/
config中是配置文件,lib文件中是依赖jar包
直接
java -jar 文件名.jar
就可以启动了