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!
Comment From: wilkinsona
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.
https://github.com/spring-projects/spring-boot/issues/22821 also relates to this. It is tracking support for building layered wars with Maven.
Comment From: wilkinsona
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 https://github.com/spring-projects/spring-boot/issues/23825 to track improving that.
Comment From: ondrejlerch
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
.
Comment From: wilkinsona
Thanks, @ondrejlerch. You make a good point about the documentation. I've opened https://github.com/spring-projects/spring-boot/issues/24105 to straighten that out.
Comment From: wilkinsona
We need some feedback from @nebhale (see https://github.com/spring-projects/spring-boot/issues/23825 for details) to progress this one.
Comment From: spring-projects-issues
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.
Comment From: wilkinsona
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.
Comment From: scottfrederick
A separate issue #24522 has been created to improve the current error message.