jsmin
jsmin

Reputation: 392

Can't build image of war file using mvn spring-boot:build-image

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?

Upvotes: 3

Views: 912

Answers (2)

Pravanjan
Pravanjan

Reputation: 1016

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

Upvotes: 2

SinisaT90
SinisaT90

Reputation: 92

You can try changing packaging from war to jar

<packaging>jar</packaging>

Upvotes: 0

Related Questions