With spring boot and task bootBuildImage(gradle), is it possible build an image based on say a tomcat image, and copy the war file into relevant webapp directory, as opposed to running an application fatjar?
I know this is possible with jib.
Thanks
This is possible when using the Paketo buildpacks (the default with Spring Boot's bootBuildImage
Gradle task), because Paketo includes a Tomcat buildpack .
It does require some configuration of the Spring Boot Gradle plugin to get a non-executable war file so that the Paketo Tomcat buildpack will detect the correct application type and configure Tomcat with the war file.
Add the following configuration to the build.gradle
file to instruct Spring Boot to create a non-executable war file as shown in the Spring Boot documentation :
war {
enabled = true
}
bootWar {
classifier = 'boot'
}
Also add the following configuration so the bootBuildImage
task will use the non-executable war file:
bootBuildImage {
jar = war.archiveFile
}
After these changes, running bootBuildImage
should show that the apache-tomcat
buildpack is participating in the image generation:
> Running creator
[creator] ===> DETECTING
[creator] 5 of 18 buildpacks participating
[creator] paketo-buildpacks/ca-certificates 1.0.1
[creator] paketo-buildpacks/bellsoft-liberica 5.2.1
[creator] paketo-buildpacks/apache-tomcat 3.1.0
[creator] paketo-buildpacks/dist-zip 2.2.2
[creator] paketo-buildpacks/spring-boot 3.5.0
Without the additional configuration you would see the paketo-buildpacks/executable-jar
buildpack instead of paketo-buildpacks/apache-tomcat
, indicating that the fat executable jar was used to launch the application instead of a war deployed to Tomcat.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.