18. docker 运行容器,提示 no main manifest attribute, in /xxxxxx.jar

问题:
docker run -p 40002:40002 intelligent-posture-image
no main manifest attribute, in /intelligent-posture-image.jar

原因:这个问题主要是因为MANIFEST.MF文件内没有指定启动Main-Class主类

三种解决方式

  1. pom.xml 中添加下方代码,再重新打包
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                        <goal>build-info</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
  1. 指定MANIFEST.MF文件内容中的启动Main-Class主类
  2. 一般情况下,java 打包成 jar 包需要在 MANIFEST.MF 中指定 Main-Class 项,以便运行 java -jar xxx.jar 时找到对应的主类。因为-jar的含义就是后面跟的jar包是有main class可独立运行,所以需要在打包成jar包时指定这个类;否则,需要在执行的时候手动指定。
    解决方案:
    在运行jar包时,使用 -cp / --classpath 来手动指定。
    java -cp xxx.jar com.juanxinc.xxx.类名
posted @ 2022-02-24 19:57  呱呱二号  阅读(995)  评论(0编辑  收藏  举报