Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support building an image when using war packaging with Maven #23823

Closed
ondrejlerch opened this issue Oct 23, 2020 · 8 comments
Closed

Support building an image when using war packaging with Maven #23823

ondrejlerch opened this issue Oct 23, 2020 · 8 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@ondrejlerch
Copy link

I am trying to create OCI image via:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>2.3.4.RELEASE</version>
    <executions>
        <execution>
            <goals>
                <goal>build-image</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <layout>WAR</layout>
    </configuration>
</plugin>

where my packaging is war:

<packaging>war</packaging>

But I am getting exception:

java.lang.IllegalArgumentException: Source must refer to an existing file, got ...jar
    at org.springframework.util.Assert.isTrue (Assert.java:121)
    at org.springframework.boot.loader.tools.Packager.<init> (Packager.java:96)
    at org.springframework.boot.loader.tools.ImagePackager.<init> (ImagePackager.java:40)
    at org.springframework.boot.maven.BuildImageMojo.lambda$getApplicationContent$1 (BuildImageMojo.java:171)
    at org.springframework.boot.maven.AbstractPackagerMojo.getConfiguredPackager (AbstractPackagerMojo.java:130)
    at org.springframework.boot.maven.BuildImageMojo.getApplicationContent (BuildImageMojo.java:171)
    at org.springframework.boot.maven.BuildImageMojo.lambda$getBuildRequest$0 (BuildImageMojo.java:156)
    at org.springframework.boot.buildpack.platform.build.BuildRequest.getApplicationContent (BuildRequest.java:181)
    at org.springframework.boot.buildpack.platform.build.Lifecycle.createContainer (Lifecycle.java:165)
    at org.springframework.boot.buildpack.platform.build.Lifecycle.run (Lifecycle.java:146)
    at org.springframework.boot.buildpack.platform.build.Lifecycle.execute (Lifecycle.java:113)
    at org.springframework.boot.buildpack.platform.build.Builder.executeLifecycle (Builder.java:122)
    at org.springframework.boot.buildpack.platform.build.Builder.build (Builder.java:71)
    at org.springframework.boot.maven.BuildImageMojo.buildImage (BuildImageMojo.java:148)
    at org.springframework.boot.maven.BuildImageMojo.execute (BuildImageMojo.java:140)

Looking at org.springframework.boot.maven.BuildImageMojo:182:

private File getJarFile() {
    // We can use 'project.getArtifact().getFile()' because that was done in a
    // forked lifecycle and is now null
    StringBuilder name = new StringBuilder(this.finalName);
    if (StringUtils.hasText(this.classifier)) {
        name.append("-").append(this.classifier);
    }
    name.append(".jar");
    return new File(this.sourceDirectory, name.toString());
}

it seems to me that just jar packaging is supported.

Shouldn't be war (and other) packaging be supported as well?

Or is there some configuration option that I missed out?

Thanks for your feedback and great work on Spring ecosystem!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 23, 2020
@wilkinsona wilkinsona changed the title Failed to execute spring-boot-maven-plugin:build-image for war packaging due to IllegalArgumentException: Source must refer to an existing file Support building an image when using war packaging with Maven Oct 23, 2020
@wilkinsona
Copy link
Member

Image building is only supported with jar packaging at the moment. Unless you are using JSPs, there's no need to use war packaging and jar packaging is strongly recommended.

#22821 also relates to this. It is tracking support for building layered wars with Maven.

@wilkinsona
Copy link
Member

This is already possible with Gradle, although it requires a little bit of manual configuration to make bootBuildImage use the output of bootWar rather than bootJar. I've opened #23825 to track improving that.

@wilkinsona wilkinsona added the type: enhancement A general enhancement label Oct 23, 2020
@ondrejlerch
Copy link
Author

ondrejlerch commented Oct 26, 2020

In my scenario jar packaging is totally fine so I will switch to that from war as you suggested.

However, I suggest to mention jar limitation in maven plugin documentation:
https://docs.spring.io/spring-boot/docs/current/maven-plugin/reference/html/#build-image
Layout parameter documentation confused me:
https://docs.spring.io/spring-boot/docs/current/maven-plugin/reference/html/#goals-build-image-parameters-details-layout
"Possible values are JAR, WAR, ZIP, DIR, NONE."

If JSPs require WAR packaging then I still suggest to add WAR packaging support for mvn spring-boot:build-image.

@wilkinsona
Copy link
Member

Thanks, @ondrejlerch. You make a good point about the documentation. I've opened #24105 to straighten that out.

@wilkinsona
Copy link
Member

We need some feedback from @nebhale (see #23825 for details) to progress this one.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Nov 10, 2020
@spring-projects-issues
Copy link
Collaborator

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Nov 17, 2020
@wilkinsona wilkinsona removed status: feedback-reminder We've sent a reminder that we need additional information before we can continue status: waiting-for-feedback We need additional information before we can continue labels Nov 17, 2020
@wilkinsona
Copy link
Member

We've had that feedback now and the default builder now behaves differently depending on whether the war artifact has a Main-Class manifest attribute. When present, the war is launched using the embedded container. We absent, the war is deployed to Tomcat.

@scottfrederick
Copy link
Contributor

A separate issue #24522 has been created to improve the current error message.

@wilkinsona wilkinsona removed the status: waiting-for-triage An issue we've not yet triaged label Jan 13, 2021
@wilkinsona wilkinsona added this to the 2.5.x milestone Jan 13, 2021
@mbhave mbhave assigned mbhave and unassigned mbhave Jan 26, 2021
@scottfrederick scottfrederick self-assigned this Feb 23, 2021
@scottfrederick scottfrederick modified the milestones: 2.5.x, 2.5.0-M3 Feb 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants