I'm trying to deploy a Java WAR file in Jetty 9 with Docker. I would like to configure things as database URI string, loglevel and such via environment variables - so that I could also use the link features of Docker.
But, if I start the application via java -jar start.jar
, the environment variables I've set are not available to the application.
What is the simplest way to pass environment variables to my application?
Using system environment variables (aka System.getenv(String)
) is not supported by Jetty's start.jar
Feel free to file a feature request with Jetty for that support.
Know however, that the Jetty start.jar
process does support properties, either as System properties, or as start properties. Either on the command line or in the ${jetty.base}/start.ini
I managed to find a solution for Jetty.
Just set JAVA_OPTIONS
in the Dockerfile and you should be good to go.
The full Dockerfile as for my case looks like this:
FROM jetty:9.2.10
MAINTAINER Me "me@me.com"
ENV spring.profiles.active=dev
ENV JAVA_OPTIONS="-Dkey=value"
ADD myWar.war /var/lib/jetty/webapps/ROOT.war