How to load system properties from a file in Wildfly 10

Wildfly has the ability to replace placeholders in specific xml files, such as peristence.xml, within your application. This can be great for allowing environment specific JPA settings for example. I’ll cover the specifics of what files support placeholder replacement in another post but for this post I want to cover the importing of an external properties file which can then be used by Wildfly for the replacements. What happens is Wildfly takes the properties and converts them all into system properties which are then also accessible in your code if you need them.

To do this simply add the -P option when starting Wildfly.

If you just have a couple of properties or don’t want to use an external file you can always specify the properties in your standalone.xml just after the extensions section.