How to add Oracle JRE to CF Java Buildpack
search cancel

How to add Oracle JRE to CF Java Buildpack

book

Article ID: 297635

calendar_today

Updated On:

Products

VMware Tanzu Application Service for VMs

Issue/Introduction

This article describes how to add and enable Oracle JRE in a customized Java Buildpack.


Environment


Cause

The Oracle JRE provides Java runtimes from the Oracle project. No versions of the JRE are available by default due to licensing restrictions. Therefore it is necessary to manually add Oracle JRE package into a custom built Java Buildpack.

Resolution

You will need to create a repository with Oracle JRE in it and configure the buildpack to use that repository. Unless otherwise configured, the version of Java that will be used is specified in config/oracle_jre.yml.

This is long-form procedure of steps outlined in https://github.com/cloudfoundry/java-buildpack/blob/master/docs/jre-oracle_jre.md


Part 1: Hosting a repository with Oracle JRE dependency:

1. Start by downloading Oracle JRE from Oracle website.

2. Create a directory and put JRE package into the directory:

mkdir oracle_cache
mv jre-8u151-linux-x64.tar.gz oracle_cache
cd oracle_cache

3. Create a file index.yml with syntax like below.

vim index.yml 
---
1.8.0_151: http://oracle-cache.apps.example.com/jre-8u151-linux-x64.tar.gz

Replace 1.8.0_151 with JRE version that you downloaded from Oracle.
Replace <apps.example.com> with app domain that repository will be hosted on.
Replace jre-8u151-linux-x64.tar.gz with the package name of Oracle JRE (file downloaded earlier).

4. Create a file manifest.yml with syntax like below:

vim manifest.yml 
---
applications:
- name: oracle_cache
  memory: 64M
  path: .
  buildpack: staticfile_buildpack

5. Push the application to any temporary space on Cloud Foundry:

cf push oracle_cache

Showing health and status for app oracle_cache in org test/space test as admin...
URLs- oracle-cache.apps.example.com
#0   running   2017-11-14 10:35:13 AM   0.0%   4.7M of 64M   82.1M of 1G

You now have a repository running which hosts your licensed Oracle JRE version!

Part 2: Customizing and building Java Buildpack with Oracle JRE1. Clone the Java buildpack: git clone https://github.com/cloudfoundry/java-buildpack.git

2. Check out the desired version of java buildpack that you want to use:

cd java-buildpack

git checkout <your desired version> eg:- git checkout v4.6

3. Edit the components.yml and disable OpenJdk and enable OracleJRE by changing commenting:

vim config/components.yml
#  - "JavaBuildpack::Jre::OpenJdkJRE"
    - "JavaBuildpack::Jre::OracleJRE"

4. Edit the oracle_jre.yml version and repository_root to match repository generated in part 1.

vim config/oracle_jre.yml
jre:
  version: 1.8.0_151
  repository_root: http://oracle-cache.apps.example.com/

Replace 1.8.0_151 with the version of Oracle JRE downloaded in part 1. Replace repository root with URL of oracle_cache static_file repository app created in part 1.

5. Run the bundle install commands to generate a customized buildpack.

export BUNDLE_PATH="./vendor"

bundle install

bundle exec rake clean package OFFLINE=true PINNED=true
...
Creating build/java-buildpack-offline-v4.6.zip

You now have a customized java buildpack installed with Oracle JRE!

Part 3: Testing and using customized Java buildpack with Oracle JRE

1. Upload the Java buildpack from the previous step to Cloud Foundry:

cf create-buildpack java_test build/java-buildpack-offline-v4.6.zip 10

Be careful with priority (10 above) as java applications by default will use highest priority java buildpack in the environment.

2. Download a sample Java app to use with new Java buildpack and push that application: cf push spring-music -b java_test

3. CF SSH to the newly pushed java app: cf ssh spring-music

4. Confirm that the Runtime Environment version matches version downloaded from Oracle:

cd /home/vcap/app/.java-buildpack/oracle_jre/bin

./java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

You have now validated that Java buildpack is working with customized Oracle JRE!

 


Additional Information

Reference: https://github.com/cloudfoundry/java-buildpack/blob/master/docs/jre-oracle_jre.md

Reference: https://github.com/cloudfoundry/java-buildpack#offline-package