How to use variables in Wildfly configuration file?

I am creating a common standalone-full.xml for all server environments and therefore should have variables for the database URL (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, when starting the server with this configuration file, it simply throws an "Unable to resolve expression" error for all such sections.

I tried to put 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 shudder a little from the dark, as I could not find the correct documentation on how to do this. I'm not even sure if this is really possible. Any help is appreciated.

+6
source share
2 answers

Instead of environment variables, you should use the properties of the Java system.

You can also pass these properties as arguments to -D in standalone.sh , for example.

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

Alternatively, you can define your properties in the properties file and pass this when you run the script with the -P option:

 bin/standalone.sh -P database.properties 
+4
source

Does this match the standard Wildfly features? For example jboss.http.port from standalone.xml

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

Perhaps you need to call standalone.sh -Djboss.http.port=8081 . Then the Wildfly http address port should be at 8081 .

It should also work for your own variables.

0
source

All Articles