pom中build信息如果是:
<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${spring.version}</version> </plugin>
的話,嘗試補全
<executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions>
即
<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${spring.version}</version> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin>
然後重新 mvn install; build success後,重新java -jar 打好的jar包進行運行。
同時要主要,打好的jar中的 META-INF中的MANIFEST.MF中需要有相應配置信息,如:
Manifest-Version: 1.0
Implementation-Title: spring-xxx-xxx
Implementation-Version: 0.0.1-SNAPSHOT
Archiver-Version: Plexus Archiver
Built-By: XXXX
Implementation-Vendor-Id: com.huyikang.practice
Spring-Boot-Version: 1.5.9.RELEASE
Implementation-Vendor: Pivotal Software, Inc.
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.huyikang.practice.eureka.Application
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Created-By: Apache Maven 3.5.2
Build-Jdk: 1.8.0_151
Implementation-URL: http://maven.apache.org
Main-Class代表了Spring Boot中啓動jar包的程序
Start-Class屬性就代表了Spring Boot程序的入口類,這個類中應該有一個main方法
Spring-Boot-Classes代表了類的路徑,所有編譯後的class文件,以及配置文件,都存儲在該路徑下
Spring-Boot-Lib表示依賴的jar包存儲的位置
這些值都是SpringBoot打包插件會默認生成的,如果沒有這些屬性,SpringBoot程序自然不能運行,就會報錯:jar中沒有主清單屬性,也就是說沒有按照SpringBoot的要求,生成這些必須的屬性。