Migrating a Java™ application from Cloud Foundry liberty-for-java buildpacks to the Paketo Buildpack for Liberty
Learn how to migrate an application that uses Cloud Foundry liberty-for-java buildpack to the Paketo Buildpack for Liberty. The Paketo Buildpack for Liberty is the strategic alternative to the liberty-for-java buildpack, which is deprecated.
About this task
Availability of the Cloud Foundry liberty-for-java buildpack on IBM® Fix Central stops in August 2024. The strategic alternative is the Paketo Buildpack for Liberty.
The Paketo Buildpack for Liberty is an open source cloud-native buildpack that provides the Liberty runtime to an application container image that can run almost anywhere. The following sections describe how to build applications that run on Liberty by using the Paketo Buildpack for Liberty, and how to use some of the Paketo Buildpack for Liberty advanced features. They also explain the differences between the Paketo Buildpack for Liberty and Cloud Foundry liberty-for-java buildpack and include comparisons between the commands that are used in each buildpack.
Before you begin
To complete the procedures that are described in the following sections, you need the following prerequisites.
- Docker
- pack CLI
- Git
- The Liberty getting started
applicationMany of the examples in the following sections use the Liberty getting started application. You can use the following commands to clone the repository and download the Liberty getting started application.
Alternatively, you can provide your own application source and replace the values in the example commands with the details for your application.git clone https://github.com/IBM-Cloud/get-started-java cd get-started-java
pack config default-builder gcr.io/paketo-buildpacks/builder:base
Building a container image from application source code
The main benefit of the Paketo Liberty Buildpack over Cloud Foundry is the ability to transform application source code into container images. You can build images directly from the application source without further instructions.
Procedure
Results
You ran the pack build command to create a container image.
Building an application with a simple WAR
In Cloud Foundry, the .war file is pushed by using the cf push command. The equivalent process for Paketo Buildpacks is described in the following procedure.
Before you begin
Procedure
Results
You created a .war file for your application and ran the pack build command to build the application from the .war file.
Comparing Cloud Foundry and Paketo buildpack commands for building an application with a simple WAR
- Cloud Foundry liberty-for-java buildpack command
- To push an application by using Cloud Foundry, run the following
command.
cf push -p myApp.war
- Paketo Buildpack for Liberty command
- The following pack build command uses cloud-native buildpacks to create an
application image from the source code.
For more information, see pack build.pack build myapp --env BP_LIBERTY_INSTALL_TYPE=wlp --env BP_JAVA_APP_SERVER=liberty --env BP_MAVEN_BUILT_ARTIFACT="target/*.war src/main/wlp/*" --buildpack paketo-buildpacks/eclipse-openj9 --buildpack paketo-buildpacks/java --path target/GetStartedJava.war
Building an application from a Liberty server
When you use the Cloud Foundry liberty-for-java buildpack, the buildpack can push a custom Liberty server configuration by using the cf push command.
When you use Paketo Buildpacks, the buildpack can build from an existing Liberty server installation directory.
Before you begin
Procedure
Results
You used options for the pack build command to build an application that runs on an existing Liberty server.
Comparing Cloud Foundry and Paketo buildpack commands for building an application from a Liberty server
- Cloud Foundry liberty-for-java buildpack command
-
To push your application from an existing Liberty server configuration, use the following command. In this example, the server name is
defaultServer
.cf push appname -p wlp/usr/servers/defaultServer
- Paketo Buildpack for Liberty command
-
To build from a Liberty server installation, change your working directory to the installation root that contains the
wlp
directory and run the following command.pack build --env BP_LIBERTY_INSTALL_TYPE=wlp --env BP_JAVA_APP_SERVER=liberty --buildpack paketo-buildpacks/eclipse-openj9 --buildpack paketo-buildpacks/java sampleapp
Building an application from a packaged Liberty server
When you use the Cloud Foundry liberty-for-java buildpack, the ./bin/server package command is used to generate a packaged server. Paketo Buildpack for Liberty uses the same command.
Procedure
Results
You used a packaged Liberty server to build an application by specifying the --path option for the pack build command.
Comparing Cloud Foundry and Paketo buildpack commands for building an application from a packaged Liberty server
- Cloud Foundry liberty-for-java buildpack commands
- In Cloud Foundry buildpacks, you can push a packaged server to IBM Cloud® by using the Liberty
server package command. Run the ./bin/server package command
from the installation
directory.
This command generates a serverName.zip file in the server directory. The following command pushes the .zip file to IBM Cloud.wlp/bin/server package serverName --include=usr
cf push yourAppName -p wlp/usr/servers/defaultServer/serverName.zip
- Paketo Buildpack for Liberty commands
- Use the Liberty
server package command to create a packaged server. Run the following command
from the Liberty installation
wlp
directory.bin/server package serverName --include=usr
Then, supply the packaged server to the build by using the--path
argument for the pack build command.
For more information about the server package command, see Packaging a Liberty server from the command line.pack build --env BP_LIBERTY_INSTALL_TYPE=wlp --env BP_JAVA_APP_SERVER=liberty --buildpack paketo-buildpacks/eclipse-openj9 --buildpack paketo-buildpacks/java --path usr/servers/your-app-server-name/your-app-server-name.zip sampleapp2
Building an application by using UBI images
For more information, see Liberty container images.
In the following steps, you create three files: bootstrap.sh, Dockerfile, and builder.toml.
Procedure
Results
You used UBI images by creating bootstrap.sh, Dockerfile, and builder.toml files, creating a custom builder, and running the pack build command.
Comparing Cloud Foundry and Paketo buildpack commands for building an application by using UBI images
- Cloud Foundry liberty-for-java buildpack command
-
Cloud Foundry supports pushing applications from container registries such as Google Container Registry (GCR) and Amazon Elastic Container Registry (ECR).
Run the following cf push command for an application that is stored in a container.
cf push APP-NAME --docker-image REPO/IMAGE:TAG
For more information about pushing an application in Cloud Foundry by using a docker image, see Deploying an App with Docker.
- Paketo Buildpack for Liberty commands for building the stack image
-
When you create a
Dockerfile
, you can use different images by specifying the UBI images in the first line of theDockerfile
, as described inRunning Web Sphere Liberty in a container.After you prepare theDockerfile
for the stack, run the following commands to build the run and build images that you need.docker build -t <image-name>-run:latest --target run . docker build -t <image-name>-build:latest --target build .
Providing server configuration file at build time
You can provide server configuration at build time and build with that configuration by specifying the build artifact and file location in the pack build command.
In Cloud Foundry, custom Liberty configurations are provided in the cf push command by installing the Liberty to your workstation and specifying the location in the command.
With Paketo Buildpack for Liberty commands, the following server configuration files can be included in the application image.
- server.xml
- server.env
- bootstrap.properties
Before you begin
In addition to the prerequisites, you must have Maven or Gradle to provide your configuration as a build artifact.
The following procedure assumes that you are using the Liberty getting started application and that you provide your chosen configuration in the src/main/wlp directory. The procedure provides your configuration to the build as a Maven or Gradle build artifact.
Procedure
Results
Comparing Cloud Foundry and Paketo buildpack commands for providing server configuration at build time
- Cloud Foundry liberty-for-java buildpack command
-
- Install Liberty to your workstation. For more information, see Server directory.
- Run the following command to push your application and custom
configuration.
cf push yourappname -p wlp/usr/servers/defaultServer
- Paketo Buildpack for Liberty command
- Run the following command to provide your custom configuration at build time. This example uses
the Liberty getting started application, with
custom configuration provided in the src/main/wlp
directory.
pack build myapp --env BP_LIBERTY_INSTALL_TYPE=wlp --env BP_JAVA_APP_SERVER=liberty --env BP_MAVEN_BUILT_ARTIFACT="target/*.[ejw]ar src/main/wlp/*" --buildpack paketo-buildpacks/eclipse-openj9 --buildpack paketo-buildpacks/java
Building an application that uses a Liberty profile
Buildpacks can use profiles to install a liberty runtime with a specified set of features
included. For example, the jakartaee9
profile includes features that support the
full Jakarta EE 9.x platform.
In Cloud Foundry, different Liberty profiles are specified in the cf push command by setting the environment variables.
Similarly, in Paketo buildpacks, you can specify a Liberty profile in the pack
build command by using the --env BP_LIBERTY_PROFILE environment variable
option. If no profile is specified, the default profile in both WebSphere® Liberty and Open Liberty is
kernel
.
Procedure
Results
You built an application to run on a specific Liberty profile by using the --env option for the pack build command.
Comparing Cloud Foundry and Paketo buildpack commands for building an application that uses a Liberty profile
- Cloud Foundry liberty-for-java buildpack command
-
The Cloud Foundry liberty-for-java buildpack supports the following profiles:
javaee6
,javaee7
,javaee8
.Install a profile by running the following cf command and environment variable. This example uses the
javaee8
profile.cf set-env myapp JBP_CONFIG_LIBERTY "app_archive: {features: [javaee8]}”
- Paketo Buildpack for Liberty command
-
Install a profile by running the pack build --env command and including the --env BP_LIBERTY_PROFILE environment variable option. For example, to include the
jakartaee9
profile, run the following command.pack build app_name_here --env BP_LIBERTY_INSTALL_TYPE=wlp --env BP_JAVA_APP_SERVER=liberty --env BP_LIBERTY_PROFILE=jakartaee9 --env BP_MAVEN_BUILT_ARTIFACT="target/*.[ejw]ar src/main/wlp/*" --buildpack paketo-buildpacks/eclipse-openj9 --buildpack paketo-buildpacks/java
Installing custom features
In Paketo Buildpacks, custom features are configured by using a volume mount to the /features directory that contains the feature JARs, manifests, and feature descriptor.
The feature manifest is a TOML
file that is called
features.toml, which contains a list of features that are to be installed on
the server.
A feature has the following properties.
- name
- The name of the feature to enable. Use symbolic name of the feature that you use to enable the feature in the server.xml.
- uri
- The URI for the feature. The
file
URI scheme is the only currently supported scheme. - version
- The version of the feature.
- dependencies
- A list of features that the custom feature depends on.
The following procedure uses the dummyCache
example feature, which includes the
cache.dummy_1.0.0.mf, and cache.dummy_1.0.0.jar files.
Procedure
Results
You installed custom Liberty features by using the pack build command. For more information about installing Liberty features with Paketo Buildpack for Liberty, see Installing Open Liberty or WebSphere Liberty features.
Comparing Cloud Foundry and Paketo buildpack commands for installing custom features
- Cloud Foundry liberty-for-java buildpack command
-
- In the root directory of your application, create a
.profile.d
directory. The.profile.d
directory must have the following contents../instfeature.sh ./.feature ./.feature/cache.dummy_1.0.0.mf ./.feature/cache.dummy_1.0.0.jar
The.feature
directory contains the custom feature JAR and manifest files.Instfeature.sh
is a script with the following content.#!/bin/sh echo "Installing custom feature" echo "Making directories...." mkdir -p /home/vcap/app/wlp/usr/extension/lib/features echo "Copying files..." cp /home/vcap/app/.profile.d/.feature/cache.dummy_1.0.0.jar /home/vcap/app/wlp/usr/extension/lib/. cp /home/vcap/app/.profile.d/.feature/cache.dummy_1.0.0.mf /home/vcap/app/wlp/usr/extension/lib/features/.
When you run the cf push command in the next step, Cloud Foundry detects the
.profile.d
directory and runs any scripts that the directory contains. TheInstfeature.sh
script copies the manifest and feature JAR to the user feature path and user bundle path. - Run the following command.
cf push
- In the root directory of your application, create a
- Paketo Buildpack for Liberty command
- After you create your custom feature files as described in the
previous procedure, run the following
command.
pack build --env BP_LIBERTY_INSTALL_TYPE=wlp --env BP_JAVA_APP_SERVER=liberty --volume path-to-features-directory:/features --buildpack paketo-buildpacks/eclipse-openj9 --buildpack paketo-buildpacks/java myapp
Installing interim fixes
In Paketo Buildpack for Liberty, you can apply an interim fix for the Liberty runtime by using a volume mount.
Before you begin
- Only the archive versions of Liberty interim fixes are supported.
- The interim fixes are in a directory named
ifixes
ifixes
directory with the following
structure.
ifixes/
220012-wlp-archive-ifph50342.jar
Procedure
Results
You applied an interim fix by using the --volume option for the pack
build command to map your local ifixes/
directory to the
/ifixes
location in the container. For more information about applying interim
fixes with Paketo Buildpack for Liberty, see Installing Open Liberty or WebSphere Liberty interim fixes.
Comparing Cloud Foundry and Paketo buildpack commands for installing interim fixes
- Cloud Foundry liberty-for-java buildpack commands
-
- Create the .profile.d/.ifixes directory in the root of the application that you want to deploy to IBM Cloud.
- Place the interim fix
.jar
file in the.profile.d/.ifixes/
directory. - If the interim fix file can cleanly apply against the IBM
Cloud version of Liberty, create
ifix.sh
file in the.profile.d
directory with the following content.#!/bin/sh echo "Applying iFixes" $HOME/.java/jre/bin/java -jar $HOME/.profile.d/.ifixes/<ifix filename>.jar --installLocation $HOME/.liberty/
If the interim fix file cannot cleanly apply, create the following script in the
.profile.d
directory.
The#!/bin/sh echo "Applying iFixes" unzip $HOME/.profile.d/.ifixes/<ifix filename>.jar lib/*.jar -d $HOME/.liberty
.profile.d
directory in this example has the following contents..profile.d/ .profile.d/.ifixes/16003-wlp-archive-IFPI68805.jar .profile.d/ifix.sh
- After you deploy your application, look the following message that indicates which interim fixes
were
applied.
CWWKF0015I: The server has the following interim fixes active in the runtime: PIXXXXX. For a full listing of installed fixes run: productInfo version --ifixes
- Paketo Buildpack for Liberty command
- Apply an interim fix to the Liberty
runtime by using a volume mount. Specify the --volume option to map your local
ifixes/ directory to the /ifixes location in the
container.
pack build --env BP_LIBERTY_INSTALL_TYPE=wlp --env BP_JAVA_APP_SERVER=liberty --volume /path/to/ifixes:/ifixes --buildpack paketo-buildpacks/eclipse-openj9 --buildpack paketo-buildpacks/java sampleapp2