Configuring the Cloud Foundry Java Buildpack

Until now the preferred way to make changes to the Java Buildpack has been to fork it and edit one of the yaml files in the config directory. If a bigger change is required then the code has to be edited directly. For a configuration change forking can be a pain so there is a new feature that allows an environment variable to be set on an application that will update the value of an existing configuration property.

The environment variable name must be capitalized, match the name of configuration file to override minus the .yml extension and have a prefix of JBP_CONFIG. The value of the variable should be valid in-line yaml. For example, to change the default version of Java to 7 and make an adjustment to the memory heuristics:

cf set-env myapp JBP_CONFIG_OPEN_JDK_JRE '[jre: {version: 1.7.0_+}, 
                 memory_calculator: {memory_heuristics: {heap: 85, stack: 10}}]'

EDIT: This example has been updated.

Notice that an array is being used so that multiple values can be updated by separating them with a comma. If only one value is being updated then square brackets must still be used to specify an array. If the key or value of a property contains a special character such as : it should be escaped with double quotes. For example, to change the default repository path for the buildpack:

cf set-env myapp JBP_CONFIG_REPOSITORY '[ default_repository_root: "" ]'

Once the new environment variable has been applied, a running application will need to be restaged for the changes to take effect. Environment variable can also be specified in the applications manifest file. This means that changes can be checked in to source control and don’t need to be specified with every push.

    JBP_CONFIG_REPOSITORY: '[ default_repository_root: "" ]'

Only existing values can be changed, attempts to add a new configuration property or replace values with hashes (and vies-versa) will result in a warning message and be ignored.

This new feature will be released shortly and become available in Cloud Foundry but until then it is available for use from the master branch of the Java Buildpack repo.


  1. Krzysztof Balka

    Very useful page!
    Do you know how to setup gc output via env variables ?

    I’m trying to setup it like this:
    cf set-env myapp JBP_CONFIG_JAVA_OPTS ‘[ java_opts :”-verbose:gc” ]’
    but without any good result.

    • Chris


      By default the java_opts property is disabled and the buildpack won’t let you add new properties which includes enabling ones that are commented out. This isn’t a problem for your use case though as you can still set Java opts using environment variables without going through the config files. Try the following.

      cf set-env myapp JAVA_OPTS '-verbose:gc'

      I haven’t actually tested that but it should work. Hope it helps.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.