英文:
Can't build image of war file using mvn spring-boot:build-image
问题
以下是翻译好的内容:
我正在尝试使用 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 文件,我该如何解决这个问题?
英文:
I'm trying to build a Docker image to my project (which is packaged to war file, not jar file) using Spring Boot build-image goal and I got this error
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
This the command which I used to build the image
mvn spring-boot:build-image -Dspring-boot.build-image.imageName=projectio/demo
And this is my pom file
<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>
The plugin seems to search for a jar file and I'm building a war file how can I fix this?
答案1
得分: 2
当前版本的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
英文:
The current version of spring(2.3.5) does not support to build an image of a war file type using mvn spring-boot:build-image or gradle bootBuildImage.
They have decided to add this feature to 2.5X release. The below milestone link has detail about the same.
https://github.com/spring-projects/spring-boot/issues/22821
https://github.com/spring-projects/spring-boot/milestone/185
答案2
得分: 0
你可以尝试将打包方式从war更改为jar
<packaging>jar</packaging>
英文:
You can try changing packaging from war to jar
<packaging>jar</packaging>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论