Roberto
Roberto

Reputation: 2236

Configuring a Jetty application with env variables

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?

Upvotes: 4

Views: 4824

Answers (2)

Yuriy Kravets
Yuriy Kravets

Reputation: 1263

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 "[email protected]"
ENV spring.profiles.active=dev
ENV JAVA_OPTIONS="-Dkey=value"
ADD myWar.war /var/lib/jetty/webapps/ROOT.war

Upvotes: 3

Joakim Erdfelt
Joakim Erdfelt

Reputation: 49472

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

Upvotes: 1

Related Questions