Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] How to pass different values at runtime (like db credentials) to a WAR file?

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.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" "">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
    <Set name="contextPath">/ws</Set>
    <Set name="virtualHosts">
            <Array type="java.lang.String">
    <Set name="war"><SystemProperty name="jetty.base"/>/webapps/ws-servlet-0.1-SNAPSHOT.war</Set>

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 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?

Best regards

Back to the top