这个是在公司做项目的时候看老大的文件才了解的,我觉得这个打包方式非常的cooooooool,所以,自己实现了一下,并且记录下来
首先生成一个springboot项目,然后在resources那里新建config文件夹和script文件夹,script文件夹新建startup.bat和startup.sh文件,这两个是win系统和linux系统的脚本
startup.bat:xxx.jar是你jar包的名字
title 配置系统
java -jar -Xms256m -Xmx512m xxx.jar --spring.profiles.active=prod --spring.config.location=file:./config/,D:/dl-middleware-6.0/config/
startup.sh:同上
java -jar -Xms256m -Xmx512m xxx.jar --spring.profiles.active=prod --spring.config.location=file:./config/,D:/dl-middleware-6.0/config/
在resources文件夹新建assembly.xml文件,把下面内容复制到assembly.xml文件
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>package</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${basedir}/src/main/resources/config</directory>
<includes>
<include>*.yml</include>
<include>*.xml</include>
</includes>
<filtered>true</filtered>
<outputDirectory>${file.separator}config</outputDirectory>
</fileSet>
<fileSet>
<directory>src/main/resources/script</directory>
<outputDirectory>${file.separator}</outputDirectory>
</fileSet>
<fileSet>
<directory>${project.build.directory}/lib</directory>
<outputDirectory>${file.separator}lib</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>${file.separator}</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
</assembly>
这个文件主要用于配置打包的jar包的配置属性
最后,在pom.xml处把下面代码复制到<plugins>标签里面,这个主要用于增加插件
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-config</id>
<phase>process-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<includes>
<exclude>config/**</exclude>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<!--拷贝依赖到jar外面的lib目录 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-lib</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<excludeTransitive>false</excludeTransitive>
<stripVersion>false</stripVersion>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/resources/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
在lifecycle依次运行clean,package和install,跑完之后查看源代码的位置有zip包
里面有config文件夹(主要用于放默认配置文件),lib是你所有依赖的文件夹,其他就不介绍了
(win系统)解压,打开那个文件夹,shfit加右键,打开cmd,运行测试一下,输入startup.bat