"C:\Program Files\Java\jdk-17\bin\java.exe" -Dmaven.multiModuleProjectDirectory=D:\workspace-pro\mall\font-mall-boot -Djansi.passthrough=true -Dmaven.home=D:\tools\apache-maven-3.8.4 -Dclassworlds.conf=D:\tools\apache-maven-3.8.4\bin\m2.conf "-Dmaven.ext.class.path=C:\Program Files\JetBrains\IntelliJ IDEA 2023.3.6\plugins\maven\lib\maven-event-listener.jar" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2023.3.6\lib\idea_rt.jar=58294:C:\Program Files\JetBrains\IntelliJ IDEA 2023.3.6\bin" -Dfile.encoding=UTF-8 -classpath D:\tools\apache-maven-3.8.4\boot\plexus-classworlds-2.6.0.jar;D:\tools\apache-maven-3.8.4\boot\plexus-classworlds.license org.codehaus.classworlds.Launcher -Didea.version=2023.3.6 -s D:\tools\apache-maven-3.8.4\conf\settings.xml -Dmaven.repo.local=D:\tools\mvnRepo_1.1 -DskipTests=true com.spotify:docker-maven-plugin:1.2.2:build -P rdc,pre,!test [INFO] Scanning for projects... [WARNING] [WARNING] Some problems were encountered while building the effective model for com.reeji:font-mall-boot:jar:1.0-SNAPSHOT [WARNING] 'build.plugins.plugin.version' for org.springframework.boot:spring-boot-maven-plugin is missing. @ line 180, column 21 [WARNING] [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build. [WARNING] [WARNING] For this reason, future Maven versions might no longer support building such malformed projects. [WARNING] [INFO] [INFO] ----------------------< com.reeji:font-mall-boot >---------------------- [INFO] Building font-mall-boot 1.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- docker-maven-plugin:1.2.2:build (default-cli) @ font-mall-boot --- [INFO] Using authentication suppliers: [ConfigFileRegistryAuthSupplier] [INFO] Copying D:\workspace-pro\mall\font-mall-boot\target\font-mall-boot-1.0-SNAPSHOT.jar -> D:\workspace-pro\mall\font-mall-boot\target\docker\font-mall-boot-1.0-SNAPSHOT.jar [INFO] Copying D:\workspace-pro\mall\font-mall-boot\target\classes\docker\Dockerfile -> D:\workspace-pro\mall\font-mall-boot\target\docker\Dockerfile [INFO] Building image font-mall-boot Step 1/11 : FROM adoptopenjdk/openjdk11 as builder ---> 82de38fa2bb6 Step 2/11 : WORKDIR application ---> Using cache ---> 9c3dec2fcc03 Step 3/11 : ADD . . ---> 4ca0dbfb3ed9 Step 4/11 : RUN java -Djarmode=layertools -jar font-mall-boot-1.0-SNAPSHOT.jar extract ---> Running in 737deb4e4a34 no main manifest attribute, in font-mall-boot-1.0-SNAPSHOT.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 5.736 s [INFO] Finished at: 2025-08-04T14:57:11+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal com.spotify:docker-maven-plugin:1.2.2:build (default-cli) on project font-mall-boot: Exception caught: The command '/bin/sh -c java -Djarmode=layertools -jar font-mall-boot-1.0-SNAPSHOT.jar extract' returned a non-zero code: 1 -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException Process finished with exit code 1
时间: 2025-08-05 19:46:12 浏览: 9
### 问题分析
在构建 Docker 镜像时出现错误提示 `no main manifest attribute`,通常表示 JAR 包中缺少主类信息,即未正确指定 `Main-Class` 属性。该属性是 Java 运行时识别程序入口点的关键信息。在 Spring Boot 项目中,通常由 `spring-boot-maven-plugin` 负责在打包过程中添加该属性。
如果构建的 JAR 包无法通过 `java -jar` 正常运行,并且在 Docker 容器中也报出相同错误,说明构建的 JAR 包本身没有正确包含主清单属性,这通常与 Maven 的插件配置有关。
### 解决方案
在 Maven 的 `pom.xml` 文件中,确保配置了 `spring-boot-maven-plugin` 插件,并且指定了 `repackage` 目标,以便在构建过程中生成可执行的 JAR 包。以下是标准配置示例:
```xml
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
```
该配置确保构建的 JAR 包包含完整的主清单信息,从而支持通过 `java -jar` 命令运行。若项目中存在多个模块或需要指定主类,应进一步配置 `<mainClass>` 属性,例如:
```xml
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.example.demo.DemoApplication</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
```
上述配置确保构建的 JAR 包包含正确的主类声明,避免因缺少主清单属性导致运行失败[^2]。
此外,在 Dockerfile 中确保使用正确的 JAR 文件名,并且该文件已正确打包并放置在构建上下文中。例如:
```dockerfile
FROM openjdk:11
MAINTAINER yyf
COPY *.jar /app.jar
EXPOSE 8082
ENTRYPOINT ["java", "-jar", "app.jar"]
```
确保 `COPY` 指令引用的 JAR 文件与 Maven 构建输出一致,且包含完整的主清单属性[^1]。
---
###
阅读全文