SpringBoot打包所有依赖jar包和配置⽂件全部分离
常规的springboot打包后,只⽣成⼀个jar包,配置⽂件和所有依赖包都在⼀起,当有⼀点点改动,上线时需要把整个包发布上去,有些不太⽅便。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="/POM/4.0.0"
xmlns:xsi="/2001/XMLSchema-instance"
xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId&i.dubbo</groupId>
<artifactId>SpringBootPackageTest</artifactId>
<version>0.0.1</version>
<name>SpringBootPackageTest</name>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<!-- 去除resources下的所有⽂件 -->
<excludes>
<exclude>**/*.properties</exclude>
<exclude>**/*.xml</exclude>
<exclude>**/*.yml</exclude>
<exclude>static/**</exclude>
<exclude>templates/**</exclude>
<exclude>templates/**</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<layout>ZIP</layout>
<includes>
<!-- 打包时,本jar包不包含其他依赖包,否则打出的jar包还是很⼤ --> <include>
<groupId>nothing</groupId>
<artifactId>nothing</artifactId>
</include>
</includes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<!-- ⽤于复制⽂件等配置 -->
<descriptor&l</descriptor>
</descriptors>
<finalName>${project.artifactId}</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
maven打包本地jar包<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
<assembly
xmlns="/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="/2001/XMLSchema-instance"
xsi:schemaLocation="/plugins/maven-assembly-plugin/assembly/1.1.2 /xsd/assembly-1.1.2.xsd"> <id>release</id>
<includeBaseDirectory>true</includeBaseDirectory>
<formats>
<!-- 打出包的后缀, -->
<format&</format>
<format>dir</format>
</formats>
<fileSets>
<fileSet>
<directory>target/classes</directory>
<outputDirectory>config</outputDirectory>
<includes>
<include>*.yml</include>
<include>*.xml</include>
<include>*.properties</include>
</includes>
</fileSet>
<fileSet>
<directory>target/classes</directory>
<outputDirectory>resources</outputDirectory>
<includes>
<include>static/**</include>
<include>templates/**</include>
</includes>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<!-- 将项⽬所有依赖包拷贝到发布包的lib⽬录下 -->
<outputDirectory>lib</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
</dependencySet>
</dependencySets>
</assembly>
项⽬结构如下:
使⽤eclipse maven install 打包后,结构如下:
< 包中没有SpringBootPackageTest-0.0.1.jar包, 解压SpringBootPackageTest-0.0.后需要⼿动考进去。
运⾏: java -Dloader.path=./lib,config -jar SpringBootPackageTest-0.0.1.jar
访问:
暂时简单测试没问题。这种⽅式只适合不带页⾯的后台程序运⾏(如前后端分离的后端程序),有页⾯的⼯程暂时没到解决⽅法。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论