How to avoid hardcoding Connection details in the datasource file?

If you don’t want to hard-code the Connection details of your Datasource in the -ds.xml file, then you can define your connection-url attribute as a System Property:


Then you can start-up JBoss passing the parameter database-url with the -D flag. Example: -Ddatabase.url=jdbc:mysql://localhost:3306/myschema

As an alternative, you can use an environment variable to reference the connection-url:


To learn more about using environment variables in WildFly check this article: How to use environment variables in WildFly configuration (standalone.xml or host.xml)