Specifying the Java Version for Cloud Foundry Applications on IBM Cloud

2 min read

IBM Cloud offers several types of services and the IBM Cloud Foundry Platform-as-a-Service (PaaS) offering is one of the most popular and widely used.

The underlying Cloud Foundry (CF) technology allows you to deploy and run your applications without managing servers or clusters, and you can integrate CF with the IBM Cloud Continuous Delivery (CD) service to automate the building and deployment of applications. 

Goal

IBM Cloud Foundry and IBM Cloud Continuous Delivery service are two different technologies, but some users gets confused with the way they work, especially when you specify a Java version to build your applications. In this post, I will explain the differences between the two and how to manage the Java version for your build.

Prerequisites

The Java version depends on the environment

While you can dynamically specify which engine to use for Node.js in package.json, you compile and run your Java application using the Java installed on the machine. Since the space and method that Cloud Foundry and Continuous Delivery service build are different, the installed Java and ways to specify the version to use are different.

How to specify which Java version to use in Cloud Foundry

In order to specify which Java version to use in Cloud Foundry, you need to specify which buildpack to use and set which Java version to use.

First, you need to find out the available buildpacks using the ibmcloud cli:

ibmcloud cf buildpacks

Once you get the filename, research the buildpack on the internet to find out if the desired Java version is included.

Finally, you specify which version of Java to use by following the Configuration and Extension. If you'd like to specify the Open OpenJDK JRE version to run in v7, you need to run the following command:

ibmcloud cf set-env your_app_name JBP_CONFIG_OPEN_JDK_JRE '{jre: { version: 1.7.0_+ }}'

How to specify which Java version to use in Continuous Delivery

On the other hand, if you build with the Continuous Delivery service, you are not going to use buildpacks. Instead, you can use versioned base images to run pipeline jobs to make sure that you are using the specific tools, libraries, and runtimes. Versioned base images help you to make sure that the bits that make up the application and the environment that you deploy the application to are consistent. You can control when the tools, libraries, or runtimes for your application change and update them when it makes sense during the development cycle.

Again, you compile and run your Java application using the Java installed on the machine. So firstly, you need to find out which base image version has the target java version installed. Check the # java-version section in the documentation.

If you need to specify the base image version, open the Delivery Pipeline page and click the three vertical dots to access the list of options:

If you need to specify the base image version, open the Delivery Pipeline page and click the three vertical dots to access the list of options:

Then, click Configure Pipeline. In the Image version tab, select the default image version to use for all jobs in your pipeline and click Save:

Then, click Configure Pipeline. In the Image version tab, select the default image version to use for all jobs in your pipeline and click Save.

What's next?

Every time vulnerabilities are found in Java, a new version gets released with fixes. Sometimes you need time to catch up with the latest version and leave your applications running in previous versions. This technique can help you adapt changes in this rapidly evolving environment. If you have any questions or concerns, please feel free to contact IBM Cloud Support team.

Be the first to hear about news, product updates, and innovation from IBM Cloud