This is a basic walkthrough of how to use the Boost Maven Plugin to package an existing Spring Boot application into a Liberty executable jar and to build a docker image from it.
To get started, you will first need a basic Spring Boot application. You can clone the following project from Spring's Getting Started Guide:
git clone [email protected]:spring-guides/gs-spring-boot.git
Move into the completed directory of the Spring Boot project.
cd gs-spring-boot/complete
Open the pom.xml and add the following plugin definition after the spring-boot-maven-plugin:
<plugin>
<groupId>io.openliberty.boost</groupId>
<artifactId>boost-maven-plugin</artifactId>
<version>0.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
Run the Maven package command as you normally would when building a Spring Boot Application:
mvn clean package
The jar file produced is a Liberty executable server with the thinned Spring Boot application deployed to it. To run the application, simply run the jar:
java -jar target/gs-spring-boot-0.1.0.jar
You can optionally run your application using the provided boost goals:
mvn boost:start
, mvn boost:stop
, mvn boost:run
, and mvn boost:debug
.
Go to http://localhost:8080
and you should see the following displayed in the browser:
Greetings from Spring Boot!
With Boost, you can easily create a Spring Boot application Docker image that uses Liberty from your Spring Boot application. Note that you must first have Docker installed and running.
Edit the Boost plugin definition in the pom.xml to the following:
<plugin>
<groupId>io.openliberty.boost</groupId>
<artifactId>boost-maven-plugin</artifactId>
<version>0.1</version>
<executions>
<execution>
<goals>
<goal>docker-build</goal>
</goals>
</execution>
</executions>
</plugin>
Now, run mvn clean install
to build your docker image.
The docker-build
goal creates a Liberty specific Dockerfile in the root folder of the Spring Boot project in the absence of a Dockerfile and builds the docker image.
Run docker images
and you should see the newly created docker image called gs-spring-boot
.
To run the container, issue the following:
docker run -p 9080:9080 gs-spring-boot
Go to http://localhost:9080
and you should again see the following displayed in the browser:
Greetings from Spring Boot!