无法使用mvn spring-boot:build-image构建war文件的映像。

huangapple go评论75阅读模式
英文:

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

&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&lt;parent&gt;
	&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
	&lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
	&lt;version&gt;2.3.3.RELEASE&lt;/version&gt;
	&lt;relativePath/&gt;
&lt;/parent&gt;
&lt;groupId&gt;com.pdr&lt;/groupId&gt;
&lt;artifactId&gt;demo&lt;/artifactId&gt;
&lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
&lt;packaging&gt;war&lt;/packaging&gt;
&lt;name&gt;demo&lt;/name&gt;

&lt;properties&gt;
	&lt;java.version&gt;1.8&lt;/java.version&gt;
&lt;/properties&gt;

&lt;dependencies&gt;
	&lt;dependency&gt;
		&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
		&lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
	&lt;/dependency&gt;

	&lt;dependency&gt;
		&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
		&lt;artifactId&gt;spring-boot-starter-tomcat&lt;/artifactId&gt;
		&lt;scope&gt;provided&lt;/scope&gt;
	&lt;/dependency&gt;
	&lt;dependency&gt;
		&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
		&lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
		&lt;scope&gt;test&lt;/scope&gt;
		&lt;exclusions&gt;
			&lt;exclusion&gt;
				&lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;
				&lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;
			&lt;/exclusion&gt;
		&lt;/exclusions&gt;
	&lt;/dependency&gt;
&lt;/dependencies&gt;

&lt;build&gt;
	&lt;plugins&gt;
		&lt;plugin&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
		&lt;/plugin&gt;
	&lt;/plugins&gt;
&lt;/build&gt;

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

&lt;packaging&gt;jar&lt;/packaging&gt;

huangapple
  • 本文由 发表于 2020年9月17日 23:37:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/63941519.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定