[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [jetty-users] How to pass different values at runtime (like db credentials) to a WAR file?
|
Hi,
On Tue, Jun 11, 2019 at 6:06 PM Alexander Farber
<alexander.farber@xxxxxxxxx> wrote:
>
> Good evening,
>
> I am running Jetty on CentOS 7 Linux with the following command:
>
> /usr/bin/java -Djdbc.drivers=org.postgresql.Driver -jar /usr/share/java/jetty-distribution-9.4.18.v20190429/start.jar jetty.home=/usr/share/java/jetty-distribution-9.4.18.v20190429 jetty.base=/var/www/jetty-base-ru jetty.http.host=127.0.0.1 jetty.http.port=8080
>
> It serves a Wordpress web site + a small WAR servlet programmed by me:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
> <Configure class="org.eclipse.jetty.webapp.WebAppContext">
> <Set name="contextPath">/ws</Set>
> <Set name="virtualHosts">
> <Array type="java.lang.String">
> <Item>blah.com</Item>
> <Item>www.blah.com</Item>
> </Array>
> </Set>
> <Set name="war"><SystemProperty name="jetty.base"/>/webapps/ws-servlet-0.1-SNAPSHOT.war</Set>
> </Configure>
>
> This works well for since over a year, thank you so much.
>
> However now a need has emerged to run several instances of the WAR configured with different values at the runtime (like database credentials and FCM/Amazon ids and secrets).
>
> I understand that I could pass them as environment variables before starting Jetty with the above command and then read them with System.getenv(...).
>
> However I would prefer a "less global" way to configure just my servlet during the runtime...
>
> While studying https://www.eclipse.org/jetty/documentation/9.4.18.v20190429/configuring-contexts.html I wonder if that is possible through putting the values into the webapps XML file?
>
> What would be the XML syntax please and how to access those values from Java source code?
See https://www.eclipse.org/jetty/documentation/9.4.18.v20190429/configuring-specific-webapp-deployment.html.
--
Simone Bordet
----
http://cometd.org
http://webtide.com
Developer advice, training, services and support
from the Jetty & CometD experts.