mysql驱动没有主清单属性_解决 xx.jar中没有主清单属性 问题

今天新写的SpringBoot项目打jar包部署的时候遇到一个问题,xxx.jar包中没有主清单属性。如下图所示:

4d5f3d1221bb63b0f38c63ba56983f84.png

主清单属性是jar包中MANIFEST.MF文件中的一个属性,MANIFEST.MF文件位于jar包的META_INF路径下

5c2e1daddf968420dc5ca587a86ac0b0.png

打开MANIFEST.MF文件,里面有如下属性:

Manifest-Version: 1.0Implementation-Title: com.imooc

Implementation-Version: 1.0-SNAPSHOT

Archiver-Version: Plexus Archiver

Built-By: liu

Implementation-Vendor-Id: com.zh

Created-By: Apache Maven 3.6.3Build-Jdk: 1.8.0_111

Implementation-URL: http://www.example.com

Implementation-Vendor: Pivotal Software, Inc.

再贴一个正常的MANIFEST.MF:

Manifest-Version: 1.0Implementation-Title: common

Implementation-Version: 0.0.1-SNAPSHOT

Spring-Boot-Version: 2.1.5.RELEASE

Main-Class: org.springframework.boot.loader.JarLauncher

Start-Class: com.zh.common.management.CommonApplication

Spring-Boot-Classes: BOOT-INF/classes/Spring-Boot-Lib: BOOT-INF/lib/Build-Jdk-Spec: 1.8Created-By: Maven Archiver 3.4.0

对比发现有问题的jar包文件中多了Archiver-Version、Built-By、Implementation-Vendor-Id三个属性,少了Spring-Boot-Version、Main-Class、Start-Class、Spring-Boot-Classes、Spring-Boot-Lib五个Springboot相关的属性。

Main-Class:属性值代表了Spring Boot中启动jar包的程序,值为 org.springframework.boot.loader.JarLauncher,这个就是Springboot启动项目的类

Start-Class:属性值代表了Spring Boot程序的入口类,即XXXApplication类

Spring-Boot-Classes:属性值代表了类路径,所有编译后的class文件,以及配置文件,都存储在该路径下

Spring-Boot-Lib:属性值代表了表示依赖的jar包存储的位置

以上这些属性是Springboot打包插件默认生成,缺少这些属性项目无法运行。

所以需要再pom文件中添加Springboot打包插件:

org.springframework.boot

spring-boot-maven-plugin

按照一个正统的教程到这里应该就结束了,但是....

一顿操作之后你的项目可能会OK了,但也可能仍然有问题

我项目的POM文件是自动生成的在build标签里面附带了一个pluginManagement标签,我们知道pluginManagement一般是在父pom中,pluginManagement中包裹的插件,子pom可以直接引用,但也必须在子pom中写出来。当我百思不得其解的时候 ,我比较了我之前项目的pom文件,发现没有这个标签,然后我尝试删除pluginManagement标签之后。再次编译的jar包终于运行成功。这里pluginManagement的某种我不知道的特性可能对Springboot打包插件的生效产生了某种不可名状的干扰。

org.springframework.boot

spring-boot-maven-plugin

org.apache.maven.plugins

maven-compiler-plugin

8

8

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值