irpas技术客

Spring Boot:jar中没有主清单属性_独行客-编码爱好者_springboot 中没有主清单属性

未知 6619

使用Spring Boot微服务搭建框架,在eclipse和Idea下能正常运行,但是在打成jar包部署或者直接使用java -jar命令的时候,提示了xxxxxx.jar中没有主清单属性:

D:\hu-git\spring-xxx-xxx\target>java -jar spring-cloud-eureka-0.0.1-SNAPS

HOT.jar

spring-xxx-xxx-0.0.1-SNAPSHOT.jar中没有主清单属性

通过maven打jar包:mvn install, 或者在IDE中右击选择Run as -> maven install。

在这里有一个问题就是主清单属性是什么?

以SpringBoot为例,jar包中包含了三个文件夹:BOOT-INF,META-INF,org,可以把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的要求,生成这些必须的属性。

我的包的MANIFEST.MF? 文件如下:

Manifest-Version: 1.0

Archiver-Version: Plexus Archiver

Built-By: gezongyang

Created-By: Apache Maven 3.3.9

Build-Jdk: 1.8.0_181

?信息不全,因此启动不了。

解决办法:

在pom中添加一个SpringBoot的构建的插件,然后重新运行 mvn install即可。

<plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>com.xxl.job.admin.AdminApplication</mainClass> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build>


1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,会注明原创字样,如未注明都非原创,如有侵权请联系删除!;3.作者投稿可能会经我们编辑修改或补充;4.本站不提供任何储存功能只提供收集或者投稿人的网盘链接。

标签: #springboot #中没有主清单属性 #使用spring #jar #install