Configuring a Jetty application with env variables

孤人 提交于 2019-12-10 17:47:29

问题


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?


回答1:


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




回答2:


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


来源:https://stackoverflow.com/questions/27157904/configuring-a-jetty-application-with-env-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!