Quick tips for running Java applications on OpenShift

Apache Commons Configuration:

It’s pretty common to need to set hostname or a port for your service in OpenShift. If you’re using Apache Commons Configuration, there’s a quick an easy way to access variables exported by the cartridges. You can address the environment variables using the ‘env’ prefix.

Here’s an example:


Apache Log4j:

If you’re using the Do It Yourself (DIY) Cartridge, you may want to set the location of your log files inside the ‘logs’ directory, so that you can read them with rhc tail. Since log4j is capable of referencing system properties, you can do that quite easily in log4j.

1. During startup set a system property that points to ${OPENSHIFT_DIY_LOG_DIR}. You can do that either by modifying your start up script or editing the startup script.

In my applications, I modify the application startup script to read JAVA_OPTS during startup and then set my startup hook to something like this:

2. Modify the appenders on log4j.properties file to point to that location by using the system property:



Published by

Otavio Piske

Just another nerd

Leave a Reply

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