阅读:13974回复:0
Spring-Boot项目离线打成jar包一键运行
Spring-Boot项目离线打成jar包一键运行
注:由于社区限制了图片数量不能超过10个,因此有部分图片不能上传,请到此链接继续查看:Spring-Boot项目离线打成jar包一键运行 Eclipse平台打包 经过测试,Hearken平台离线打成的jar包执行有问题,使用Eclipse打包运行成功
图片:1.png ![]()
图片:2.png ![]()
图片:3.png ![]()
图片:4.png ![]() IDEA平台打包
图片:5.png ![]()
图片:6.png ![]()
图片:7.png ![]()
图片:8.png ![]() Module: 模块,选择需要打包的模块。如果程序没有分模块,那么只有一个可以选择的。 Main Class:选择程序的入口类。 extract to the target JAR:抽取到目标JAR。选择该项则会将所依赖的jar包全都打到一个jar文件中。 copy to the output directory and link via manifest:将依赖的jar复制到输出目录并且使用manifest链接它们。 Direct for META-INF/MANIFEST.MF: 如果上面选择了 "copy to ... "这一项,这里需要选择生成的manifest文件在哪个目录下。 Include tests: 是否包含tests。 一般这里不选即可。
图片:9.png ![]() 再在刚创建的文件夹上右键 =》 Add Copy of => File, 选择刚才创建的MANIFEST.MF文件添加进去, 图片:10.png ![]() 点击 Apply =》 Ok
如果无法解决依赖包冲突问题,而又可以通过更改依赖包加载顺序来解决,则可以在MANIFEST.MF文件里面更改Class-Path中各依赖包的顺序(越往后越后加载) 附:使用maven插件打包(包含本地依赖文件) 在pom.xml文件中配置以下的打包插件,路径根据具体情况更改(这里是将依赖包放在项目根目录的lib目录下)。该配置会将所有依赖打成一个jar包 <build> <plugins> <!-- spring-boot-maven-plugin (提供了直接运行项目的插件:如果是通过parent方式继承spring-boot-starter-parent则不用此插件) --> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> <configuration> <executable>true</executable> <fork>true</fork> <!--<addResources>true</addResources>--> <!--<includeSystemScope>true</includeSystemScope>--> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>prepare-package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>false</overWriteSnapshots> <overWriteIfNewer>true</overWriteIfNewer> </configuration> </execution> </executions> </plugin> <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> <compilerArgs> <arg>-extdirs</arg> <arg>${project.basedir}/lib</arg> </compilerArgs> </configuration> </plugin> </plugins> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include>**/*.*</include> </includes> </resource> <resource> <directory>${project.basedir}/lib</directory> <targetPath>BOOT-INF/lib/</targetPath> <includes> <include>**/*.jar</include> </includes> </resource> </resources> </build> [熊伟于2019-03-19 15:01编辑了帖子]
|
|