For distributed platforms

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.

The following sections describe some of the advanced features for Liberty applications that use the Paketo Buildpack for Liberty.

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 application
    Many 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.
    git clone https://github.com/IBM-Cloud/get-started-java
    cd get-started-java
    Alternatively, you can provide your own application source and replace the values in the example commands with the details for your application.
If you're new to Paketo Buildpacks, you can set a default builder so that you don't need to set a builder every time you build an image. After you install the pack CLI, run the following command to set a default builder.
pack config default-builder gcr.io/paketo-buildpacks/builder:base

Building a container image from application source code

About this task

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

  1. On the command line, go to the root directory in your application source code.
  2. Run the following command to build your container image.
    pack build myapp --env BP_JAVA_APP_SERVER=liberty --env BP_LIBERTY_INSTALL_TYPE=wlp --env BP_MAVEN_BUILT_ARTIFACT="target/*.[ejw]ar src/main/liberty/config/" --buildpack paketo-buildpacks/eclipse-openj9 --buildpack paketo-buildpacks/java

    The build output shows the container image that is created and is similar to the following example.

    
    [builder]   Process types:
    [builder]     websphere-liberty-runtime: server run defaultServer (direct)
    ===> EXPORTING
    [exporter] Reusing layer 'paketo-buildpacks/eclipse-openj9:helper'
    [exporter] Reusing layer 'paketo-buildpacks/eclipse-openj9:java-security-properties'
    [exporter] Reusing layer 'paketo-buildpacks/eclipse-openj9:jre'
    [exporter] Reusing layer 'paketo-buildpacks/ca-certificates:helper'
    [exporter] Adding layer 'paketo-buildpacks/liberty:base'
    [exporter] Adding layer 'paketo-buildpacks/liberty:helper'
    [exporter] Adding layer 'paketo-buildpacks/liberty:websphere-liberty-runtime-kernel'
    [exporter] Adding layer 'launch.sbom'
    [exporter] Adding 1/1 app layer(s)
    [exporter] Reusing layer 'launcher'
    [exporter] Adding layer 'config'
    [exporter] Adding layer 'process-types'
    [exporter] Adding label 'io.buildpacks.lifecycle.metadata'
    [exporter] Adding label 'io.buildpacks.build.metadata'
    [exporter] Adding label 'io.buildpacks.project.metadata'
    [exporter] Setting default process type 'websphere-liberty-runtime'
    [exporter] Saving myapp...
    [exporter] *** Images (da44647b5d45):
    [exporter]       myapp
    [exporter] Reusing cache layer 'paketo-buildpacks/eclipse-openj9:jdk'
    [exporter] Reusing cache layer 'paketo-buildpacks/syft:syft'
    [exporter] Adding cache layer 'paketo-buildpacks/maven:application'
    [exporter] Adding cache layer 'paketo-buildpacks/maven:cache'
    [exporter] Reusing cache layer 'paketo-buildpacks/maven:maven'
    [exporter] Adding cache layer 'paketo-buildpacks/liberty:websphere-liberty-runtime-kernel'
    [exporter] Adding cache layer 'cache.sbom'
    Successfully built image myapp
    

Results

You ran the pack build command to create a container image.

Building an application with a simple WAR

About this task

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

In addition to the prerequisites, you must have a JDK and Maven to compile the deployed artifact.

Procedure

  1. To generate a .war file, run the mvn install command from the application root directory.

    This command generates a GetStartedJava.war file in the target directory.

  2. Run the pack build command to create your container image.

    Use the --path option to provide the location of the .war that you built in the previous step. Also, specify the --buildpacks option so that the OpenJ9 JRE is included in your container image, as shown in the following example.

    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
  3. Verify that your features and environment variables are specified in the build output.

    The following example demonstrates the build output. Verify that the OpenJ9 JRE is used in the DETECTING section. If the build is successful, the output ends with the Successfully built image myapp message.

    
    ===> DETECTING
    [detector] 7 of 25 buildpacks participating
    [detector] paketo-buildpacks/eclipse-openj9    9.8.2
    [detector] paketo-buildpacks/ca-certificates   3.5.0
    [detector] paketo-buildpacks/bellsoft-liberica 9.10.1
    [detector] paketo-buildpacks/syft              1.23.0
    [detector] paketo-buildpacks/liberty           3.0.0
    [detector] paketo-buildpacks/dist-zip          5.4.0
    [detector] paketo-buildpacks/spring-boot       5.20.0
    ...
    ===> BUILDING
    ...
    [builder] Paketo Buildpack for Liberty 3.0.0
    [builder]   https://github.com/paketo-buildpacks/liberty
    [builder]   Build Configuration:
    [builder]     $BP_JAVA_APP_SERVER       liberty  the application server to use
    [builder]     $BP_LIBERTY_FEATURES               A space separated list of liberty features to install.
    [builder]     $BP_LIBERTY_INSTALL_TYPE  wlp      Install type of Liberty
    [builder]     $BP_LIBERTY_PROFILE                The Liberty profile to install
    [builder]     $BP_LIBERTY_SERVER_NAME            Name of the server to use
    [builder]     $BP_LIBERTY_VERSION       *        Which version of the Liberty runtime to install
    [builder]   Launch Configuration:
    [builder]     $BPL_LIBERTY_LOG_LEVEL             Sets the logging level
    [builder]     $BP_LIBERTY_CONTEXT_ROOT           Context root to use for app
    [builder]     $BP_LIBERTY_SERVER_NAME            Name of the server to use
    [builder]   Launch Helper: Reusing cached layer
    [builder]   Open Liberty Config: Contributing to layer
    [builder]     Writing env.launch/BPI_LIBERTY_SERVER_NAME.default
    [builder]     Writing env.launch/JAVA_TOOL_OPTIONS.append
    [builder]     Writing env.launch/JAVA_TOOL_OPTIONS.delim
    [builder]     Writing env.launch/WLP_USER_DIR.default
    [builder]   WebSphere Liberty (Kernel) 22.0.12: Reusing cached layer
    [builder]   Process types:
    [builder]     websphere-liberty-runtime: server run defaultServer (direct)
    ===> EXPORTING
    [exporter] Reusing layer 'paketo-buildpacks/eclipse-openj9:helper'
    [exporter] Reusing layer 'paketo-buildpacks/eclipse-openj9:java-security-properties'
    [exporter] Reusing layer 'paketo-buildpacks/eclipse-openj9:jre'
    [exporter] Reusing layer 'paketo-buildpacks/ca-certificates:helper'
    [exporter] Reusing layer 'paketo-buildpacks/liberty:base'
    [exporter] Reusing layer 'paketo-buildpacks/liberty:helper'
    [exporter] Reusing layer 'paketo-buildpacks/liberty:websphere-liberty-runtime-kernel'
    [exporter] Reusing layer 'launch.sbom'
    [exporter] Adding 1/1 app layer(s)
    [exporter] Reusing layer 'launcher'
    [exporter] Adding layer 'config'
    [exporter] Reusing layer 'process-types'
    [exporter] Adding label 'io.buildpacks.lifecycle.metadata'
    [exporter] Adding label 'io.buildpacks.build.metadata'
    [exporter] Adding label 'io.buildpacks.project.metadata'
    [exporter] Setting default process type 'websphere-liberty-runtime'
    [exporter] Saving myapp...
    [exporter] *** Images (51ca11a0fd63):
    [exporter]       myapp
    [exporter] Reusing cache layer 'paketo-buildpacks/eclipse-openj9:jdk'
    [exporter] Reusing cache layer 'paketo-buildpacks/syft:syft'
    [exporter] Reusing cache layer 'paketo-buildpacks/liberty:websphere-liberty-runtime-kernel'
    [exporter] Adding cache layer 'cache.sbom'
    Successfully built image myapp
    
  4. Run your application locally with the docker run command.
    After you verify the output of the pack build command, run the following command.
    docker run --rm -p 9080:9080 myapp
  5. Go to the following address in your browser.
    https://locahost:9080

    The Liberty getting started application displays a welcome screen with an input field for your name.

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.
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
For more information, see pack build.

Building an application from a Liberty server

About this task

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

Before you build the application from an existing Liberty server installation directory, you must complete the initial setup of the Liberty server. Setting up a Liberty server is outside the scope of these instructions.

Procedure

  1. From the command line, go to the wlp directory in your Liberty server installation root directory.
  2. Run the following pack build 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
  3. To verify that the correct server directory is used, look for the websphere-liberty-runtime: server run server1 message in the build output. The build output is similar to the following example.
    
    ...
    [builder] Paketo Buildpack for Liberty 3.1.0
    [builder]   https://github.com/paketo-buildpacks/liberty
    [builder]   Build Configuration:
    [builder]     $BP_JAVA_APP_SERVER       liberty  the application server to use
    [builder]     $BP_LIBERTY_FEATURES               A space separated list of liberty features to install.
    [builder]     $BP_LIBERTY_INSTALL_TYPE  wlp      Install type of Liberty
    [builder]     $BP_LIBERTY_PROFILE                The Liberty profile to install
    [builder]     $BP_LIBERTY_SERVER_NAME   server1  Name of the server to use
    [builder]     $BP_LIBERTY_VERSION       *        Which version of the Liberty runtime to install
    [builder]   Launch Configuration:
    [builder]     $BPL_LIBERTY_LOG_LEVEL             Sets the logging level
    [builder]     $BP_LIBERTY_CONTEXT_ROOT           Context root to use for app
    [builder]     $BP_LIBERTY_SERVER_NAME   server1  Name of the server to use
    [builder]   Launch Helper: Contributing to layer
    [builder]     Creating /layers/paketo-buildpacks_liberty/helper/exec.d/linker
    [builder]   Open Liberty Config: Contributing to layer
    [builder]     Writing env.launch/BPI_LIBERTY_SERVER_NAME.default
    [builder]     Writing env.launch/JAVA_TOOL_OPTIONS.append
    [builder]     Writing env.launch/JAVA_TOOL_OPTIONS.delim
    [builder]     Writing env.launch/WLP_USER_DIR.default
    [builder]   WebSphere Liberty (Kernel) 22.0.12: Reusing cached layer
    [builder]   Process types:
    [builder]     websphere-liberty-runtime: server run server1 (direct)
    ...
    Successfully built image sampleapp
    

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

About this task

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

  1. Run the following server package command from the Liberty installation directory to create a packaged server.
    bin/server package serverName --include=usr
  2. Provide the packaged server to the build by specifying its location in the --path option for the pack build command.
    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
    The following example shows the expected build output.
    
    ...
    [builder] Paketo Buildpack for Liberty 3.1.0
    [builder]   https://github.com/paketo-buildpacks/liberty
    [builder]   Build Configuration:
    [builder]     $BP_JAVA_APP_SERVER       liberty  the application server to use
    [builder]     $BP_LIBERTY_FEATURES               A space separated list of liberty features to install.
    [builder]     $BP_LIBERTY_INSTALL_TYPE  wlp      Install type of Liberty
    [builder]     $BP_LIBERTY_PROFILE                The Liberty profile to install
    [builder]     $BP_LIBERTY_SERVER_NAME            Name of the server to use
    [builder]     $BP_LIBERTY_VERSION       *        Which version of the Liberty runtime to install
    [builder]   Launch Configuration:
    [builder]     $BPL_LIBERTY_LOG_LEVEL             Sets the logging level
    [builder]     $BP_LIBERTY_CONTEXT_ROOT           Context root to use for app
    [builder]     $BP_LIBERTY_SERVER_NAME            Name of the server to use
    [builder]   Launch Helper: Contributing to layer
    [builder]     Creating /layers/paketo-buildpacks_liberty/helper/exec.d/linker
    [builder]   Open Liberty Config: Contributing to layer
    [builder]     Writing env.launch/BPI_LIBERTY_SERVER_NAME.default
    [builder]     Writing env.launch/JAVA_TOOL_OPTIONS.append
    [builder]     Writing env.launch/JAVA_TOOL_OPTIONS.delim
    [builder]     Writing env.launch/WLP_USER_DIR.default
    [builder]   WebSphere Liberty (Kernel) 22.0.12: Contributing to layer
    [builder]     Downloading from https://repo1.maven.org/maven2/com/ibm/websphere/appserver/runtime/wlp-kernel/22.0.0.12/wlp-kernel-22.0.0.12.zip
    ...
    [builder]   Process types:
    [builder]     websphere-liberty-runtime: server run server1 (direct)
    ...
    ===> EXPORTING
    ...
    Successfully built image sampleapp2
    

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.
wlp/bin/server package serverName --include=usr
This command generates a serverName.zip file in the server directory. The following command pushes the .zip file to IBM Cloud.
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.
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
For more information about the server package command, see Packaging a Liberty server from the command line.

Building an application by using UBI images

About this task

The Paketo Buildpack for Liberty can use the WebSphere Liberty runtime that is provided in the stack run image. This runtime includes optimizations and configurations that are provided by IBM Cloud Container Registry (ICR). For more information, see Liberty container images.

In the following steps, you create three files: bootstrap.sh, Dockerfile, and builder.toml.

Procedure

  1. In a directory of your choosing, create a bootstrap.sh file with the following contents.
    
    #!/usr/bin/env bash
    
    main() {
      readonly LIBERTY_USR_DIRS=(
        "/workspace/wlp/usr"
        "/workspace/usr"
        "/layers/paketo-buildpacks_liberty/base/wlp/usr"
      )
    
      for liberty_usr_dir in "${LIBERTY_USR_DIRS[@]}"; do
        if [[ -d "${liberty_usr_dir}" ]]; then
          local usr_dir="${liberty_usr_dir}"
          break
        fi
      done
    
      cp -rf "${usr_dir}/." "${BPI_LIBERTY_RUNTIME_ROOT}/usr/"
    
      # Call Liberty runtime's bootstrap script
      docker-server.sh "${@}"
    }
    
    main "${@}"
    

    This script is necessary to grab the configuration and application that is created by the buildpacks. Confirm that the bootstrap.sh script is executable before you proceed to the next step.

  2. Create a Dockerfile in the same directory that you used for the bootstrap.sh file.

    The Dockerfile must be similar to the following example. This example pulls the websphere-liberty:kernel-java11-openj9-ubi version.

    
    # RUN IMAGE
    FROM  icr.io/appcafe/websphere-liberty:kernel-java11-openj9-ubi as run
    
    ENV CNB_USER_ID=1001
    ENV CNB_GROUP_ID=0
    ENV CNB_STACK_ID="io.buildpacks.stacks.liberty"
    LABEL io.buildpacks.stack.id="io.buildpacks.stacks.liberty"
    
    # Set environment variables used by the Open Liberty CNB.
    ENV SERVICE_BINDING_ROOT=/platform/bindings
    ENV BPI_LIBERTY_ROOT=/opt/ibm
    ENV BPI_LIBERTY_RUNTIME_ROOT=${BPI_LIBERTY_ROOT}/wlp
    ENV WLP_USER_DIR=${BPI_LIBERTY_RUNTIME_ROOT}/usr
    ENV PATH=${BPI_LIBERTY_ROOT}/helpers/runtime:${BPI_LIBERTY_RUNTIME_ROOT}/bin:${PATH}
    
    # Set user and group (as declared in the base image)
    USER ${CNB_USER_ID}
    
    COPY --chown=${CNB_USER_ID}:${CNB_GROUP_ID} bootstrap.sh ${BPI_LIBERTY_ROOT}/helpers/runtime/
    
    # This script will add the requested server configurations (optionally), apply any interim fixes (optionally) and populate caches to optimize runtime
    RUN configure.sh
    
    FROM registry.access.redhat.com/ubi8/ubi:8.5 as build
    
    # BUILD IMAGE
    ENV CNB_USER_ID=1001
    ENV CNB_GROUP_ID=0
    ENV CNB_STACK_ID="io.buildpacks.stacks.liberty"
    LABEL io.buildpacks.stack.id="io.buildpacks.stacks.liberty"
    
    # Provides hint to the Open Liberty buildpack which version of Liberty is being used at build time
    ENV BPI_LIBERTY_RUNTIME_ROOT=/opt/ibm/wlp
    RUN mkdir -p ${BPI_LIBERTY_RUNTIME_ROOT}
    
    RUN useradd --uid ${CNB_USER_ID} --gid ${CNB_GROUP_ID} -m -s /bin/bash cnb
    
    RUN yum -y install git wget jq && wget https://github.com/sclevine/yj/releases/download/v5.0.0/yj-linux -O /usr/local/bin/yj && chmod +x /usr/local/bin/yj
    
    # Set user and group (as declared in the base image)
    USER ${CNB_USER_ID}
    
  3. Run the following commands to build the run and build images. Replace image-name with the image name that you want to use.
    
    docker build -t image-name-run:latest --target run .
    docker build -t image-name-build:latest --target build .
    

    If the command succeeds, the docker build -t image-name-run:latest --target run . command has the following output.

    
     => [internal] load build definition from Dockerfile                                                                                                                                    0.0s
     => => transferring dockerfile: 37B                                                                                                                                                     0.0s
     => [internal] load .dockerignore                                                                                                                                                       0.0s
     => => transferring context: 2B                                                                                                                                                         0.0s
     => [internal] load metadata for icr.io/appcafe/open-liberty:kernel-slim-java11-openj9-ubi                                                                                              0.3s
     => [internal] load build context                                                                                                                                                       0.0s
     => => transferring context: 514B                                                                                                                                                       0.0s
     => CACHED [run 1/3] FROM icr.io/appcafe/open-liberty:kernel-slim-java11-openj9-ubi@sha256:43b1b7a94fa6fc428767e6b39368907ca319979203a0b6ee0d7af983eff4402e                             0.0s
     => [run 2/3] COPY --chown=1001:0 bootstrap.sh /opt/ol/helpers/runtime/                                                                                                                 0.0s
     => [run 3/3] RUN configure.sh                                                                                                                                                          4.6s
     => exporting to image                                                                                                                                                                  0.1s
     => => exporting layers                                                                                                                                                                 0.1s
     => => writing image sha256:89212c1d996f6fe08f3d0410bc09ccca33d60315a50682db6a34da8420b718a8                                                                                            0.0s
     => => naming to docker.io/library/starter-image-run:latest                                                                                                                             0.0s
    

    If the command succeeds, the docker build -t image-name-build:latest --target build . command has the following output.

    
     => [internal] load build definition from Dockerfile                                                                                                                                    0.0s
     => => transferring dockerfile: 37B                                                                                                                                                     0.0s
     => [internal] load .dockerignore                                                                                                                                                       0.0s
     => => transferring context: 2B                                                                                                                                                         0.0s
     => [internal] load metadata for registry.access.redhat.com/ubi8/ubi:8.5                                                                                                                0.8s
     => [build 1/4] FROM registry.access.redhat.com/ubi8/ubi:8.5@sha256:798025840cb82140df8d05775f7f55fff3b16a599bd5ca76b11594f7a9a595fa                                                    0.0s
     => CACHED [build 2/4] RUN mkdir -p /opt/ol/wlp                                                                                                                                         0.0s
     => CACHED [build 3/4] RUN useradd --uid 1001 --gid 0 -m -s /bin/bash cnb                                                                                                               0.0s
     => CACHED [build 4/4] RUN yum -y install git wget jq && wget https://github.com/sclevine/yj/releases/download/v5.0.0/yj-linux -O /usr/local/bin/yj && chmod +x /usr/local/bin/yj       0.0s
     => exporting to image                                                                                                                                                                  0.0s
     => => exporting layers                                                                                                                                                                 0.0s
     => => writing image sha256:c8325b72e4110a245c993930f75a89d3f525e66158358a4e79bcd6127b9d27c7                                                                                            0.0s
     => => naming to docker.io/library/starter-image-build:latest                                                                                                                           0.0s
    
  4. Create a custom builder by creating a builder.toml file with the following contents. Replace the stack.run-image and stack.build-image values with the image-name value that you chose in the previous step.
    
    [[buildpacks]]
      uri = "docker://gcr.io/paketo-buildpacks/ca-certificates"
    
    [[buildpacks]]
      uri = "docker://gcr.io/paketo-buildpacks/eclipse-openj9"
    
    [[buildpacks]]
      uri = "docker://gcr.io/paketo-buildpacks/syft"
    
    [[buildpacks]]
      uri = "docker://gcr.io/paketo-buildpacks/leiningen"
    
    [[buildpacks]]
      uri = "docker://gcr.io/paketo-buildpacks/gradle"
    
    [[buildpacks]]
      uri = "docker://gcr.io/paketo-buildpacks/maven"
    
    [[buildpacks]]
      uri = "docker://gcr.io/paketo-buildpacks/liberty"
    
    [[buildpacks]]
      uri = "docker://gcr.io/paketo-buildpacks/procfile"
    
    [[buildpacks]]
      uri = "docker://gcr.io/paketo-buildpacks/environment-variables"
    
    [[buildpacks]]
      uri = "docker://gcr.io/paketo-buildpacks/image-labels"
    
    [[order]]
    
      [[order.group]]
        id = "paketo-buildpacks/ca-certificates"
        optional = true
    
      [[order.group]]
        id = "paketo-buildpacks/eclipse-openj9"
        optional = false
    
      [[order.group]]
        id = "paketo-buildpacks/syft"
        optional = true
    
      [[order.group]]
        id = "paketo-buildpacks/gradle"
        optional = true
    
      [[order.group]]
        id = "paketo-buildpacks/maven"
        optional = true
    
      [[order.group]]
        id = "paketo-buildpacks/liberty"
        optional = true
    
      [[order.group]]
        id = "paketo-buildpacks/procfile"
        optional = true
    
      [[order.group]]
        id = "paketo-buildpacks/environment-variables"
        optional = true
    
      [[order.group]]
        id = "paketo-buildpacks/image-labels"
        optional = true
    
    [stack]
      id = "io.buildpacks.stacks.liberty"
      run-image = "image-name-run:latest"
      build-image = "image-name-build:latest"
    
  5. Run the following command to use the builder you created:
    pack -v builder create mybuilder:latest --config builder.toml

    The command output is similar to the following example.

    
    Pulling image starter-image-run:latest
    Pulling image starter-image-build:latest
    Creating builder mybuilder:latest from build-image starter-image-build:latest
    ...
    Status: Image is up to date for gcr.io/paketo-buildpacks/image-labels:latest
    Creating builder with the following buildpacks:
    -> paketo-buildpacks/ca-certificates@3.4.0
    -> paketo-buildpacks/eclipse-openj9@9.7.0
    -> paketo-buildpacks/syft@1.21.0
    -> paketo-buildpacks/leiningen@4.4.0
    -> paketo-buildpacks/gradle@6.8.0
    -> paketo-buildpacks/maven@6.11.0
    -> paketo-buildpacks/liberty@2.4.0
    -> paketo-buildpacks/procfile@5.4.0
    -> paketo-buildpacks/environment-variables@4.3.0
    -> paketo-buildpacks/image-labels@4.3.0
    Adding buildpack paketo-buildpacks/image-labels@4.3.0 (diffID=sha256:6613db21bd509b876a76e2c3cca317f32141e2243d8e2a231f88517dcc88ffcf)
    Adding buildpack paketo-buildpacks/ca-certificates@3.4.0 (diffID=sha256:0c16b901029079ec6f2f154f2bcf7b82c932bbfe8bd7665e9d753b0869491fb2)
    Adding buildpack paketo-buildpacks/eclipse-openj9@9.7.0 (diffID=sha256:fbe1a86cae3b45034e26c29d46f60dcd289ad43f61ba98955514376c174de5ee)
    Adding buildpack paketo-buildpacks/leiningen@4.4.0 (diffID=sha256:dca34fe44b9c62ddab049fa3638703ca40d12dc3a37f83cc892d5c3a6b3b9075)
    Adding buildpack paketo-buildpacks/liberty@2.4.0 (diffID=sha256:9c8a0114133fc3aa2765216509a020983d5d16cd3bfaa5d958818344b995c083)
    Adding buildpack paketo-buildpacks/procfile@5.4.0 (diffID=sha256:8c184880fd75919ea528e3f506e93f99022eecbbcb5a797c5cf134806bb13761)
    Adding buildpack paketo-buildpacks/environment-variables@4.3.0 (diffID=sha256:0952cc879389c15fa9f4dd50fe9365d672a0ec4e751438899eda65c782fa1b4c)
    Adding buildpack paketo-buildpacks/syft@1.21.0 (diffID=sha256:e9482447bd072ccbd758e5bf6517123f724e3cd3f1ed85e76bdfc55c2e54e947)
    Adding buildpack paketo-buildpacks/gradle@6.8.0 (diffID=sha256:a707ff8bbd5a93e09a6b9973a55e096c48a9f5768865b0db25a6a36046355df6)
    Adding buildpack paketo-buildpacks/maven@6.11.0 (diffID=sha256:53d7320eb399555d2eb990958b8624ea6ff2a4beccc3b9aa8041294dd9db1b9d)
    Successfully created builder image mybuilder:latest
    
  6. Deploy a Liberty application by using the following pack build command.
    pack build myapp --builder mybuilder:latest --env BP_LIBERTY_INSTALL_TYPE="none"

    If the pack build command is successful, it has the following output. Look for the boostrap.sh server run DefaultServer (direct) and Successfully built image messages in the output.

    
    0.14.1: Pulling from buildpacksio/lifecycle
    36698cfa5275: Pull complete
    4f80531f7622: Pull complete
    Digest: sha256:56019ba74831e3444f33ee8c0201f18cc300213bac353b8b6a79c7a1669b7a49
    Status: Downloaded newer image for buildpacksio/lifecycle:0.14.1
    ===> ANALYZING
    [analyzer] Restoring data for SBOM from previous image
    ===> DETECTING
    [detector] 5 of 9 buildpacks participating
    [detector] paketo-buildpacks/ca-certificates 3.4.0
    [detector] paketo-buildpacks/eclipse-openj9  9.7.0
    [detector] paketo-buildpacks/syft            1.21.0
    [detector] paketo-buildpacks/maven           6.11.0
    [detector] paketo-buildpacks/liberty         2.4.0
    ...
    [builder] Paketo Buildpack for Liberty 2.4.0
    [builder]   https://github.com/paketo-buildpacks/liberty
    [builder]   Build Configuration:
    [builder]     $BP_JAVA_APP_SERVER             the application server to use
    [builder]     $BP_LIBERTY_FEATURES            A space separated list of liberty features to install.
    [builder]     $BP_LIBERTY_INSTALL_TYPE  none  Install type of Liberty
    [builder]     $BP_LIBERTY_PROFILE             The Liberty profile to install
    [builder]     $BP_LIBERTY_SERVER_NAME         Name of the server to use
    [builder]     $BP_LIBERTY_VERSION       *     Which version of the Liberty runtime to install
    [builder]   Launch Configuration:
    [builder]     $BPL_LIBERTY_LOG_LEVEL          Sets the logging level
    [builder]     $BP_LIBERTY_CONTEXT_ROOT        Context root to use for app
    [builder]     $BP_LIBERTY_SERVER_NAME         Name of the server to use
    [builder]   Launch Helper: Reusing cached layer
    [builder]   Open Liberty Config: Reusing cached layer
    [builder]   Process types:
    [builder]     open-liberty-stack: bootstrap.sh server run defaultServer (direct)
    ===> EXPORTING
    [exporter] Reusing layer 'paketo-buildpacks/ca-certificates:helper'
    [exporter] Reusing layer 'paketo-buildpacks/eclipse-openj9:helper'
    [exporter] Reusing layer 'paketo-buildpacks/eclipse-openj9:java-security-properties'
    [exporter] Reusing layer 'paketo-buildpacks/eclipse-openj9:jre'
    [exporter] Reusing layer 'paketo-buildpacks/liberty:base'
    [exporter] Reusing layer 'paketo-buildpacks/liberty:helper'
    [exporter] Reusing layer 'launch.sbom'
    [exporter] Reusing 1/1 app layer(s)
    [exporter] Reusing layer 'launcher'
    [exporter] Reusing layer 'config'
    [exporter] Reusing layer 'process-types'
    [exporter] Adding label 'io.buildpacks.lifecycle.metadata'
    [exporter] Adding label 'io.buildpacks.build.metadata'
    [exporter] Adding label 'io.buildpacks.project.metadata'
    [exporter] Setting default process type 'open-liberty-stack'
    [exporter] Saving myapp...
    [exporter] *** Images (1345c46d6bb6):
    [exporter]       myapp
    [exporter] Reusing cache layer 'paketo-buildpacks/eclipse-openj9:jdk'
    [exporter] Reusing cache layer 'paketo-buildpacks/syft:syft'
    [exporter] Reusing cache layer 'paketo-buildpacks/maven:application'
    [exporter] Reusing cache layer 'paketo-buildpacks/maven:cache'
    [exporter] Reusing cache layer 'paketo-buildpacks/maven:maven'
    [exporter] Reusing cache layer 'cache.sbom'
    Successfully built image myapp
    

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 Docker Hub, 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 the Dockerfile, as described in Container Images for Websphere Liberty.

After you prepare the Dockerfile 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 .
Then, use the following pack build command and specify the custom stack images and builder:
pack build myapp --builder mybuilder:latest --env BP_LIBERTY_INSTALL_TYPE="none"

Providing server configuration file at build time

About this task

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
Important: Do not put any secrets in these configuration files. The files are included in the image and can leak your secrets. For more information about how to provide secrets in your configuration, see Configuring Secrets.

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

  1. Run the pack build command and include options to specify your Maven or Gradle build artifact.
    • If the server configuration is provided with Maven applications, run the following command.
      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
    • If the server configuration is provided with Gradle applications, run the following command.
      pack build app_name_here --env BP_LIBERTY_INSTALL_TYPE=wlp --env BP_JAVA_APP_SERVER=liberty --env BP_GRADLE_BUILT_ARTIFACT="build/libs/*.[ejw]ar src/main/wlp/*" --buildpack paketo-buildpacks/eclipse-openj9 --buildpack paketo-buildpacks/java

    If the command is successful, the Successfully built image your_app_name_here message appears in the output. A warning message for the server.xml file also appears in the output: Reminder: Do not include secrets in server.xml; this file has been included in the image and that can leak your secrets.

    The output resembles the following example.
    
    ...
    [builder] Paketo Buildpack for Liberty 3.0.0
    [builder]   https://github.com/paketo-buildpacks/liberty
    [builder]   Build Configuration:
    [builder]     $BP_JAVA_APP_SERVER       liberty  the application server to use
    [builder]     $BP_LIBERTY_FEATURES               A space separated list of liberty features to install.
    [builder]     $BP_LIBERTY_INSTALL_TYPE  wlp      Install type of Liberty
    [builder]     $BP_LIBERTY_PROFILE                The Liberty profile to install
    [builder]     $BP_LIBERTY_SERVER_NAME            Name of the server to use
    [builder]     $BP_LIBERTY_VERSION       *        Which version of the Liberty runtime to install
    [builder]   Launch Configuration:
    [builder]     $BPL_LIBERTY_LOG_LEVEL             Sets the logging level
    [builder]     $BP_LIBERTY_CONTEXT_ROOT           Context root to use for app
    [builder]     $BP_LIBERTY_SERVER_NAME            Name of the server to use
    [builder]   Launch Helper: Reusing cached layer
    [builder]   Open Liberty Config: Contributing to layer
    [builder] Reminder: Do not include secrets in server.xml; this file has been included in the image and that can leak your secrets
    [builder]     Writing env.launch/BPI_LIBERTY_SERVER_NAME.default
    [builder]     Writing env.launch/JAVA_TOOL_OPTIONS.append
    [builder]     Writing env.launch/JAVA_TOOL_OPTIONS.delim
    [builder]     Writing env.launch/WLP_USER_DIR.default
    [builder]   WebSphere Liberty (Kernel) 22.0.12: Contributing to layer
    [builder]     Downloading from https://repo1.maven.org/maven2/com/ibm/websphere/appserver/runtime/wlp-kernel/22.0.0.12/wlp-kernel-22.0.0.12.zip
    [builder]     Verifying checksum
    [builder]     Expanding to /layers/paketo-buildpacks_liberty/websphere-liberty-runtime-kernel
    [builder]     Installing features...
    ...
    
  2. To run the application locally, run the following command.
    docker run --rm -p 9080:9080 myapp

Results

You specified the build artifact and file location in the pack build command to provide the server configuration at build time.

Comparing Cloud Foundry and Paketo buildpack commands for providing server configuration at build time

Cloud Foundry liberty-for-java buildpack command
  1. Install Liberty to your workstation. For more information, see Server directory.
  2. 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

About this task

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

  1. Set the --env BP_LIBERTY_PROFILE= option in the pack build command.

    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

    The following profiles are valid for WebSphere Liberty.

    • kernel
    • jakartaee9
    • javaee8
    • javaee7
    • webProfile7
    • webProfile8
    • webProfile9
  2. Check the build output to ensure the correct profile was installed.
    Check the Build Configuration section for a list of environment variables that were installed. For the jakartaee9 profile, the build output is in the logs under the Build Configuration steps for Paketo Buildpack for Liberty 3.1.0.
    
    ...
    [builder] Paketo Buildpack for Liberty 3.1.0
    [builder]   https://github.com/paketo-buildpacks/liberty
    [builder]   Build Configuration:
    [builder]     $BP_JAVA_APP_SERVER       liberty     the application server to use
    [builder]     $BP_LIBERTY_FEATURES                  A space separated list of liberty features to install.
    [builder]     $BP_LIBERTY_INSTALL_TYPE  wlp         Install type of Liberty
    [builder]     $BP_LIBERTY_PROFILE       jakartaee9  The Liberty profile to install
    [builder]     $BP_LIBERTY_SERVER_NAME               Name of the server to use
    [builder]     $BP_LIBERTY_VERSION       *           Which version of the Liberty runtime to install
    [builder]   Launch Configuration:
    [builder]     $BPL_LIBERTY_LOG_LEVEL                Sets the logging level
    [builder]     $BP_LIBERTY_CONTEXT_ROOT              Context root to use for app
    [builder]     $BP_LIBERTY_SERVER_NAME               Name of the server to use
    ...
    

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

About this task

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 would use when you want 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

  1. Create the features.toml file with the following content:
    
    [[features]]
      name = "dummyCache"
      uri = "file://features/cache.dummy_1.0.0.jar"
      version = "1.0.0"
      dependencies = ["distributedMap-1.0"]
    
  2. Add the features.toml, cache.dummy_1.0.0.mf, and cache.dummy_1.0.0.jar files to features directory.
  3. Compress the features directory by running the following command:
    
    $ tar czvf features.tar.gz *
    ./
    ./features/
    ./features.toml
    ./features/cache.dummy_1.0.0.mf
    ./features/cache.dummy_1.0.0.jar
    
  4. Run the following command to mount the feature directory to /features and use the custom features in the build.
    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
  5. Check the build output.
    A successful build output contains the following in the Paketo Buildpack for Liberty section.
    
    ...
    [builder] Paketo Buildpack for Liberty 3.1.0
    [builder]   https://github.com/paketo-buildpacks/liberty
    [builder]   Build Configuration:
    [builder]     $BP_JAVA_APP_SERVER       liberty  the application server to use
    [builder]     $BP_LIBERTY_FEATURES               A space separated list of liberty features to install.
    [builder]     $BP_LIBERTY_INSTALL_TYPE  wlp      Install type of Liberty
    [builder]     $BP_LIBERTY_PROFILE                The Liberty profile to install
    [builder]     $BP_LIBERTY_SERVER_NAME            Name of the server to use
    [builder]     $BP_LIBERTY_VERSION       *        Which version of the Liberty runtime to install
    [builder]   Launch Configuration:
    [builder]     $BPL_LIBERTY_LOG_LEVEL             Sets the logging level
    [builder]     $BP_LIBERTY_CONTEXT_ROOT           Context root to use for app
    [builder]     $BP_LIBERTY_SERVER_NAME            Name of the server to use
    [builder]   Launch Helper: Contributing to layer
    [builder]     Creating /layers/paketo-buildpacks_liberty/helper/exec.d/linker
    [builder]   Open Liberty Config: Contributing to layer
    [builder]     Writing env.launch/BPI_LIBERTY_SERVER_NAME.default
    [builder]     Writing env.launch/JAVA_TOOL_OPTIONS.append
    [builder]     Writing env.launch/JAVA_TOOL_OPTIONS.delim
    [builder]     Writing env.launch/WLP_USER_DIR.default
    [builder]   WebSphere Liberty (Kernel) 22.0.12: Contributing to layer
    [builder]     Downloading from https://repo1.maven.org/maven2/com/ibm/websphere/appserver/runtime/wlp-kernel/22.0.0.12/wlp-kernel-22.0.0.12.zip
    [builder]     Verifying checksum
    [builder]     Expanding to /layers/paketo-buildpacks_liberty/websphere-liberty-runtime-kernel
    [builder]     Installing features...
    [builder]       Initializing ...
    [builder]       Using 8 threads to download artifacts.
    [builder]       Resolving remote features. This process might take several minutes to complete.
    [builder]       Preparing assets for installation. This process might take several minutes to complete.
    [builder]       Establishing a connection to the configured Maven repository ...
    [builder]       This process might take several minutes to complete.
    [builder]       Successfully connected to the configured repository.
    [builder]       Downloading required features ...
    [builder]       Starting installation ...
    [builder]       Successfully installed feature el-3.0.
    [builder]       Successfully installed feature servlet-3.1.
    [builder]       Successfully installed feature jsp-2.3.
    [builder]       All features were successfully installed.
    [builder]       Start product validation...
    [builder]       Product validation completed successfully.
    [builder]     Writing env.launch/BPI_LIBERTY_RUNTIME_ROOT.default
    [builder]     Writing env.launch/BPL_JVM_CLASS_ADJUSTMENT.default
    [builder]     Writing env.launch/WLP_LOGGING_APPS_WRITE_JSON.default
    [builder]     Writing env.launch/WLP_LOGGING_CONSOLE_FORMAT.default
    [builder]     Writing env.launch/WLP_LOGGING_CONSOLE_SOURCE.default
    [builder]     Writing env.launch/WLP_LOGGING_JSON_ACCESS_LOG_FIELDS.default
    [builder]     Writing env.launch/WLP_LOGGING_MESSAGE_FORMAT.default
    [builder]     Writing env.launch/WLP_LOGGING_MESSAGE_SOURCE.default
    [builder]     Writing env.launch/WLP_OUTPUT_DIR.override
    [builder]   Process types:
    [builder]     websphere-liberty-runtime: server run defaultServer (direct)
    ...
    

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
  1. 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. The Instfeature.sh script copies the manifest and feature JAR to the user feature path and user bundle path.

  2. Run the following command.
    cf push
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

About this task

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
The following examples use the 220012-wlp-archive-ifph50342.jar interim fix. The interim fix located in a ifixes directory with the following structure.

ifixes/
220012-wlp-archive-ifph50342.jar

Procedure

  1. Specify the --volume option for the pack build command 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 your-app-here
  2. Check the build output.
    The build output specifies the interim fix in the Installing iFix 220012-wlp-archive-ifph50342.jar message.
    
    ...
    [builder]   WebSphere Liberty (Kernel) 22.0.12: Contributing to layer
    [builder]     Downloading from https://repo1.maven.org/maven2/com/ibm/websphere/appserver/runtime/wlp-kernel/22.0.0.12/wlp-kernel-22.0.0.12.zip
    [builder]     Verifying checksum
    [builder]     Expanding to /layers/paketo-buildpacks_liberty/websphere-liberty-runtime-kernel
    [builder]     Installing features...
    [builder]       Initializing ...
    [builder]       Using 8 threads to download artifacts.
    [builder]       Resolving remote features. This process might take several minutes to complete.
    [builder]       Preparing assets for installation. This process might take several minutes to complete.
    [builder]       Establishing a connection to the configured Maven repository ...
    [builder]       This process might take several minutes to complete.
    [builder]       Successfully connected to the configured repository.
    [builder]       Downloading required features ...
    [builder]       Starting installation ...
    [builder]       Successfully installed feature el-3.0.
    [builder]       Successfully installed feature servlet-3.1.
    [builder]       Successfully installed feature jsp-2.3.
    [builder]       All features were successfully installed.
    [builder]       Start product validation...
    [builder]       Product validation completed successfully.
    [builder]     Installing iFix 220012-wlp-archive-ifph50342.jar
    [builder]       Applying fix that is applied to Liberty install directory at /layers/paketo-buildpacks_liberty/websphere-liberty-runtime-kernel now.
    [builder]       No content has been extracted because there are no matching features in the runtime /layers/paketo-buildpacks_liberty/websphere-liberty-runtime-kernel
    [builder]       Fix has been applied successfully.
    [builder]       Successfully extracted all product files.
    ...
    

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
  1. Create the .profile.d/.ifixes directory in the root of the application that you want to deploy to IBM Cloud.
  2. Place the interim fix .jar file in the .profile.d/.ifixes/ directory.
  3. 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.

    #!/bin/sh
    echo "Applying iFixes"
    unzip $HOME/.profile.d/.ifixes/<ifix filename>.jar lib/*.jar -d $HOME/.liberty
    The .profile.d directory in this example has the following contents.
    .profile.d/
    .profile.d/.ifixes/16003-wlp-archive-IFPI68805.jar
    .profile.d/ifix.sh
  4. 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