一、打包问题
之前在IDEA中使用maven对Spring Boot的一个Demo打包时,打出来的jar包始终不能运行。jar包中的MANIFEST.MF文件仅包含了如下信息:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: fisherxxxxxx
Created-By: Apache Maven 3.6.1
Build-Jdk: 1.8.0_212
其中pom文件做了如下打包配置:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.5.RELEASE</version>
</plugin>
</plugins>
</build>
在运行打包出来的jar包时,总是报如下错误:
$ java -jar boot-monkey-1.0-SNAPSHOT.jar
boot-monkey-1.0-SNAPSHOT.jar中没有主清单属性
也按照网上的方法在File-->Project Structure...--->Artifacts里面做了相应的配置,但是始终不起作用,问题依旧存在。
二、打包问题解决方案
咨询了同事,也查找了一些解决方案。最终问题得以解决。
其实无须配置File-->Project Structure...--->Artifacts,也无需引入maven-clean-plugin,maven-package-plugin等包,只需在spring-boot-maven-plugin引入时,加入一个extension就解决了。详见如下:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${springboot.version}</version>
<executions>
<execution>
<goals>
<goal>build-info</goal>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
运行maven中的package,得到的jar包里MANIFEST.MF文件信息如下:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: fisherxxxxxx
Start-Class: com.fisher.boot.BootApplication
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Spring-Boot-Version: 2.1.5.RELEASE
Created-By: Apache Maven 3.6.1
Build-Jdk: 1.8.0_212
Main-Class: org.springframework.boot.loader.JarLauncher
boot demo的jar包目录结构如下:
共产生两个jar包,其中一个包含了工程程序文件和工程引入的外部依赖包,一个仅仅包含了工程程序文件:
至此,可以正常运行boot-monkey-1.0-SNAPSHOT.jar。