我正在尝试使用 Spring Boot build-image 目标为我的项目构建一个 Docker 镜像(打包到 war 文件,而不是 jar 文件),但我遇到了这个错误
Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:2.3.3.RELEASE:build-image failed: Source must refer to an existing file, got E:\my_project\Java\Workspace\demo\target\demo-0.0.1-SNAPSHOT.jar
这是我用来构建图像的命令
mvn spring-boot:build-image -Dspring-boot.build-image.imageName=projectio/demo
这是我的pom文件
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.3.RELEASE</version>
<relativePath/>
</parent>
<groupId>com.pdr</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>demo</name>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
该插件似乎在搜索一个 jar 文件,而我正在构建一个 war 文件,我该如何解决这个问题?
最佳答案
当前版本的spring(2.3.5)不支持使用mvn spring-boot:build-image 或gradle bootBuildImage构建war文件类型的镜像。
他们已决定将此功能添加到 2.5X 版本中。下面的里程碑链接具有相同的详细信息。
https://github.com/spring-projects/spring-boot/issues/22821
https://github.com/spring-projects/spring-boot/milestone/185
关于java - 无法使用 mvn spring-boot :build-image 构建 war 文件的镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63941519/