Appendix D. Deploying a Spring Boot application using WAR files
Red Hat does not support packaging and deploying Spring Boot applications using WAR files in this release of RHOAR.
As an alternative to the supported application packaging and deployment workflow using fat JAR files, you can package and deploy a Spring Boot application as a WAR (Web Application Archive) file. You must configure your build and deployment settings to ensure that your application builds and deploys correctly on OpenShift.
Prerequisites
- A Spring Boot application, such as a booster.
- Fabric8 Maven Plugin used to deploy your application to OpenShift.
- Spring Boot Maven Plugin used to package your application.
Procedure
Add
warpackaging to thepom.xmlfile of your project.Example
pom.xml<project ...> ... <packaging>war</packaging> ...
Ensure the the
repackageMaven goal for the Spring Boot Maven plugin is defined in thepom.xmlfile.Example
pom.xml... <build> ... <plugins> ... <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build> ...This ensures that the Spring Boot classes used to launch the application are included in the WAR file, and that the corresponding properties for these classes are defined in the
MANIFEST.mffile of the WAR file:-
Main-Class: org.springframework.boot.loader.WarLauncher -
Spring-Boot-Classes: WEB-INF/classes/ -
Spring-Boot-Lib: WEB-INF/lib/ -
Spring-Boot-Version: 1.5.16.RELEASE
-
Add the
ARTIFACT_COPY_ARGSenvironment variable to thepom.xmlfile.The Fabric8 Maven Plugin consumes this variable during the build process and ensures that the Build and Deploy tool uses the WAR file (rather than the default fat JAR file) to create the application container image:
Example
pom.xml... <profile> <id>openshift</id> <build> <plugins> <plugin> <groupId>io.fabric8</groupId> <artifactId>fabric8-maven-plugin</artifactId> <executions> ... </executions> <configuration> <images> <image> <name>${project.artifactId}:%t</name> <alias>${project.artifactId}</alias> <build> <from>registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift:${openjdk18-openshift.version}</from> <assembly> <basedir>/deployments</basedir> <descriptorRef>artifact</descriptorRef> </assembly> <env> <ARTIFACT_COPY_ARGS>*.war</ARTIFACT_COPY_ARGS> <JAVA_APP_DIR>/deployments</JAVA_APP_DIR> </env> <ports> <port>8080</port> </ports> </build> </image> </images> </configuration> </plugin> </plugins> </build> </profile> ...Add the
JAVA_APP_JARenvironment variable to thesrc/main/fabric8/deployment.ymlfile.This variable instructs the Fabric8 Maven Plugin to launch your application using the WAR file included with the container. If
src/main/fabric8/deployment.ymldoes not exist, you can create it.Example
deployment.ymlspec: template: spec: containers: ... env: - name: JAVA_APP_JAR value: ${project.artifactId}-${project.version}.warBuild and deploy your application:
mvn clean fabric8:deploy -Popenshift

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.