How to make use of variables in Wildfly configuration file?
Asked Answered
P

2

6

I am setting up a common standalone-full.xml file for all server environments, and therefore need to have variables for database URL's (and such), instead of hard coding them.

One such section in the configuration file might look like this:

<datasource jta="true" jndi-name="java:/somename" pool-name="somename" enabled="true" use-ccm="false">
                <connection-url>jdbc:mysql://${SOMENAME_DB_URL}</connection-url>
                <driver-class>com.mysql.jdbc.Driver</driver-class>
                <driver>mysql</driver>
                <pool>
                    <min-pool-size>5</min-pool-size>
                    <max-pool-size>15</max-pool-size>
                </pool>
                <security>
                    <user-name>${DB_USERNAME}</user-name>
                    <password>${DB_PASSWORD}</password>
                </security>
                <validation>
                    <validate-on-match>false</validate-on-match>
                    <background-validation>false</background-validation>
                </validation>
                <statement>
                    <share-prepared-statements>false</share-prepared-statements>
                </statement>
            </datasource>

However, upon starting the server with this config file it simply throws an "Unable to resolve expression" error for all such sections.

I've tried putting the variables in /etc/environment, as well as in the .jbossclirc file in /bin using set DB_USERNAME=mydbusername, but to no avail.

As you can see I'm fumbling a bit in the dark here since I haven't been able to find any proper documentation on how to do this. I'm not even sure if it's actually possible. Any help is greatly appreciated.

Pathos answered 10/4, 2016 at 7:39 Comment(1)
The WildFly 10 documentation you're searching for: docs.jboss.org/author/display/WFLY10/ExpressionsHailstorm
K
7

You should use Java system properties instead of environment variables.

You can also pass these properties as -D arguments to standalone.sh, e.g.

bin/standalone.sh -DDB_USERNAME=me -DDB_PASSWORD=secret

Alternatively, you can define your properties in a properties file and pass that to the startup script with a -P option:

bin/standalone.sh -P database.properties
Karimakarin answered 11/4, 2016 at 10:17 Comment(0)
D
0

Does overriding standard properties from Wildfly work that way? For example jboss.http.port from standalone.xml

   <socket-binding name="http" port="${jboss.http.port:8080}"/> 

One possibilty is to call standalone.sh -Djboss.http.port=8081. Then, Wildfly http port should be on 8081.

It should also work for your own variables.

Duncandunce answered 10/4, 2016 at 10:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.