Define Environment Variables

Page last updated:

Page last updated:

Cloud Foundry lets you externalize configuration - storing application properties in environment variables.

At runtime, environment variables are exposed to the application through its environment. You can use this for example to run your app in production mode setting the APP_MODE environment variable.

$ cf set-env my-java-app APP_MODE production
Setting env variable 'APP_MODE' to 'production' for app my-java-app in org MyOrg / space MySpace as user@smydomain.com...
OK
TIP: Use 'cf restage' to ensure your env variable changes take effect

Then restage your app as suggested using

$ cf restage my-java-app
Restaging app my-java-app in org MyOrg / space MySpace as user@mydomain.com...
-----> Downloaded app package (3M)

...

All environment variables can be accessed using System.getenv().get('ENV_VARIABLE') or new ProcessBuilder().environment().get("ENV_VARIABLE") from within your Java app.

I’ve set my environment variable
View the source for this page in GitHub