docker no main manifest attribute

一、背景

  使用docker运行jar镜像时,报错:“docker no main manifest attribute”,其实在本地使用【java -jar】运行该jar包,同样会报错“xxxx.jar中没有主清单属性”。

二、原因

  打开jar包,可以发现文件夹【META-INF】中的文件【MANIFEST.MF】有问题,少了很多属性。

三、解决办法

  1. 手动添加对应的属性,对比下面正常的文件
    Manifest-Version: 1.0
    Spring-Boot-Classpath-Index: BOOT-INF/classpath.idx
    Implementation-Title: agent-web
    Implementation-Version: 0.0.1-SNAPSHOT
    Start-Class: com.xxx.AgentWebApplication
    Spring-Boot-Classes: BOOT-INF/classes/
    Spring-Boot-Lib: BOOT-INF/lib/
    Build-Jdk-Spec: 1.8
    Spring-Boot-Version: 2.3.0.RELEASE
    Created-By: Maven Jar Plugin 3.2.0
    Implementation-Vendor: Pivotal Software, Inc.
    Main-Class: org.springframework.boot.loader.JarLauncher
  2. 如果是maven项目,则可以增加【spring-boot-maven-plugin】插件,直接打包可以运行的jar包。
    <plugins>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
    <skipTests>true</skipTests>
    </configuration>
    </plugin>
    <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
    </plugins>

     

posted @ 2022-07-27 16:35  从零开始的0  阅读(1688)  评论(0编辑  收藏  举报