SpringBoot打包实现静态文件、配置文件、jar包分离
在pom文件里面添加
<plugins> <!--定义项目的编译环境--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> <!--maven的测试用例插件,建议跳过。--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skip>true</skip> </configuration> </plugin> <!--这个是springboot的默认编译插件,他默认会把所有的文件打包成一个jar--> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> <configuration> <mainClass>com.ruoyi.RuoYiApplication</mainClass> <fork>true</fork> <addResources>true</addResources> <outputDirectory>${project.build.directory}/jar</outputDirectory> </configuration> </plugin> <!-- 打JAR包 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <!-- 不打包资源文件(配置文件和依赖包分开) --> <excludes> <exclude>*.yml</exclude> <exclude>*.properties</exclude> <exclude>mybatis/**</exclude> <exclude>static/**</exclude> </excludes> <archive> <manifest> <addClasspath>true</addClasspath> <!-- MANIFEST.MF 中 Class-Path 加入前缀 --> <classpathPrefix>lib/</classpathPrefix> <!-- jar包不包含唯一版本标识 --> <useUniqueVersions>false</useUniqueVersions> <!--指定入口类 --> <mainClass>com.ruoyi.Application</mainClass> </manifest> <manifestEntries> <!--MANIFEST.MF 中 Class-Path 加入资源文件目录 --> <Class-Path>./config/</Class-Path> </manifestEntries> </archive> <outputDirectory>${project.build.directory}</outputDirectory> </configuration> </plugin> <!-- 该插件的作用是用于复制依赖的jar包到指定的文件夹里 --> <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> <!-- 该插件的作用是用于复制指定的文件 --> <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>*.yml</include> <include>*.properties</include> <include>mybatis/**</include> <include>static/**</include> </includes> </resource> </resources> <outputDirectory>${project.build.directory}/config</outputDirectory> </configuration> </execution> </executions> </plugin> </plugins>
<mainClass>com.ruoyi.Application</mainClass>
这个位置要修改成自己启动类路径 其他可以不改
如果还有文件夹需要分离出来,就在includes的里面继续添加即可
然后clean 然后package
然后会文件会分开打包
config:所有的配置文件、静态文件会存放在config文件夹下
jar:这里面是不分离的完整jar包
lib:这是所有依赖的lib包文件
admin-4.1.0.jar :这是分离之后的jar包文件
然后启动的话 直接把文件放在同级目录,然后运行 java -jar admin-4.1.0.jar 即可
如果不需要 改回原来的pom配置即可
<plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <fork>true</fork> <!-- 如果没有该配置,devtools不会生效 --> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>3.0.0</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> <warName>${artifactId}</warName> </configuration> </plugin> </plugins> <finalName>${artifactId}</finalName>
-----------------------有任何问题可以在评论区评论,也可以私信我,我看到的话会进行回复,欢迎大家指教------------------------
(蓝奏云官网有些地址失效了,需要把请求地址lanzous改成lanzoux才可以)