I am having trouble getting environment variables to resolve On a Linux VM when I start up a WildFly java application.
<system-properties>
<property name="java.util.logging.manager" value="org.jboss.logmanager.LogManager"/>
<property name="appname.url" value="https://${env.Environment}/appname"/>
</system-properties>
When I echo that environment variable (defined in /etc/environment) I get the following:
[ ~ ]$ echo $Environment
tst
I've tried updating the standalone.xml to have this these two properties set to true:
<subsystem xmlns="urn:jboss:domain:ee:4.0">
<spec-descriptor-property-replacement>true</spec-descriptor-property-replacement>
<jboss-descriptor-property-replacement>true</jboss-descriptor-property-replacement>
Also tried updating bin/jboss-cli.xml with this setting set to true:
<resolve-parameter-values>true</resolve-parameter-values>
Starting the application using it's service (i.e., systemctl restart appname) throws errors in the logs like this:
ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([("system-property" => "appname.url")]) - failure description: "WFLYCTL0211: Cannot resolve expression 'https://${env.Environment}/appname'"
Unfortunately, this does not resolve my issue. Any ideas?
Solution for this involved a few steps to get environment variables recognized by the WildFly app's service. It isn't exactly an environment variable, it's the closest you can get. Per this thread on stackexchange, service strips all environment variables, so they cannot be referenced. Therefore, you must create a file that stores those variables and then source it in startup.
Here they are:
bin/standalone.conf
with a new line to include JAVA_OPTS="$JAVA_OPTS -Denv.Environment=$Environment"
/etc/default/appname
file so it can be sourced later on. That file only contains the line Environment=tst
/etc/init.d/appname
file with
[ -f /etc/default/appname ] && . /etc/default/appname
export Environment
systemctl daemon-reload
systemctl restart appname