时间:2021-05-20
前言
Springboot 打jar包分离lib,配置文件的方式,网上可以搜到的我都没试通。跟刘大神(大神没有博客,很可惜)讨论后,给出了这么一个解决方案,供大家参考。
部署环境
POM.xml
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://.elvish</groupId> <artifactId>test</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>test</name> <description>test</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.10.RELEASE</version> <relativePath /> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <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-starter-thymeleaf</artifactId> </dependency> </dependencies> <build> <plugins> <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>target/lib</outputDirectory> <excludeTransitive>false</excludeTransitive> <stripVersion>false</stripVersion> <includeScope>runtime</includeScope> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <excludes> <exclude>**/*.properties</exclude> <exclude>**/*.xml</exclude> <exclude>**/*.yml</exclude> <exclude>static/**</exclude> <exclude>templates/**</exclude> </excludes> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <layout>ZIP</layout> <includes> <include> <groupId>non-exists</groupId> <artifactId>non-exists</artifactId> </include> </includes> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> <configuration> <classifier>classes</classifier> <attach>false</attach> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>run</goal> </goals> <configuration> <target> <property name="dist">target/distribution</property> <property name="dist-tmp">target/distribution/tmp</property> <property name="app-name">${project.artifactId}-${project.version}</property> <mkdir dir="${dist-tmp}" /> <copy file="target/${app-name}.jar" tofile="${dist-tmp}/${app-name}.jar" /> <unzip src="${dist-tmp}/${app-name}.jar" dest="${dist-tmp}" /> <delete file="${dist-tmp}/${app-name}.jar" /> <zip destfile="${dist}/${app-name}-pages.jar"> <zipfileset dir="${dist-tmp}/META-INF" prefix="META-INF" /> <zipfileset dir="target/classes/static" prefix="static" /> <zipfileset dir="target/classes/templates" prefix="templates" /> </zip> <move file="target/${app-name}-classes.jar" todir="${dist}" /> <move todir="${dist}/3rd-lib"> <fileset dir="target/lib" /> </move> <delete dir="${dist-tmp}" /> <copy todir="${dist}"> <fileset dir="target/classes"> <include name="**/*.properties" /> <include name="**/*.xml" /> <include name="**/*.yml" /> </fileset> </copy> </target> </configuration> </execution> </executions> </plugin> </plugins> </build></project>打完包后目录结构
运行jar
java -jar -Dloader.path=.,3rd-lib test-0.0.1-SNAPSHOT-classes.jar总结
以上所述是小编给大家介绍的Spring boot 打jar包分离lib的正确配置方式,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
Spring中配置Quartz的过程:1.导入JAR包quartz需要的JAR包,已经包含在spring中,位置在spring解压后目录的\lib\quartz
发现问题前几天用eclipse打包了一个jar包,jar包里面是定义的Spring的bean。然后将jar包放到lib下,设置spring的自动扫描这个jar包
之前介绍了使用spring-boot-maven-plugin插件打jar包,会把所有的依赖文件都导入,然后变成了一个可执行的jar包。这样的不好的地方就是,
1.springboot不支持jsp打jar包,jsp只能打war包.方法:warorg.springframework.bootspring-boot-mav
默认情况下,插件spring-boot-maven-plugin会把整个项目打包成一个可运行的Jar包(即所谓的FlatJar),导致了这个Jar包很大(通常有