Create a separate file datasources instead of adding datasources in standalone.xml

72 views
Skip to first unread message

chandra s

unread,
Jul 18, 2025, 12:31:33 PM7/18/25
to WildFly
I am new to wildfly.  Is there a way can we create separate file datasource.xml instead of in standalone.xml, so that it will be easy to handle as per environment change hostname etc.,

Can you please send some code snipped for postgresql.

I followed the following process
1.  create a folder /wildfly/<version>/modules/org/postgresql/main and copied postgresql-42.7.7.jar
2. create a file module.xml in  /wildfly/<version>/modules/org/postgresql/main
<?xml version="1.0" ?>
<module xmlns="urn:jboss:module:1.1" name="org.postgresql">
  <resources>
    <resource-root path="postgresql-42.7.7.jar"/>
  </resources>
  <dependencies>
    <module name="javax.api"/>
    <module name="javax.transaction.api"/>
  </dependencies>
</module>
3. created ds1.xml in /wildfly/<wildfly version>/standalone/deployments
               <datasource jndi-name="java:/jdbc/dsn" pool-name="dsn" enabled="true">
                    <connection-url>jdbc:postgresql://hostname:5432/devdb</connection-url>
                    <driver>postgresql</driver>
                    <pool>
                        <min-pool-size>5</min-pool-size>
                        <max-pool-size>50</max-pool-size>
                    </pool>
                    <security>
                        <user-name>user</user-name>
                        <password>pwd</password>
                    </security>
                    <validation>
                        <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"/>
                        <validate-on-match>true</validate-on-match>
                        <background-validation>false</background-validation>
                        <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"/>
                    </validation>
                </datasource>
4. Added driver info in standalone.xml

                   <driver name="postgresql" module="org.postgresql">
                        <driver-class>org.postgresql.Driver</driver-class>
                    </driver>

Can you plese review and let us know how to achieve it. Thank you in advance.

Wolfgang

unread,
Jul 18, 2025, 2:55:27 PM7/18/25
to WildFly
I think this is not possible.

This might make it easier to switch environments.

In case you use maven to build and deploy your project: the WildFly Maven plugin also provides the ability to execute scripts on deploy: https://docs.wildfly.org/wildfly-maven-plugin/releases/5.1/execute-commands-mojo.html

Hope this helps

Wolfgang
Message has been deleted

chandra s

unread,
Jul 19, 2025, 8:05:36 AM7/19/25
to WildFly
Thank you for the response.

Torsten Liermann

unread,
Jul 19, 2025, 3:45:41 PM7/19/25
to WildFly

It's possible. Let this file end with -ds.xml.
At places you want to keep variable, insert the property placeholder, e.g., ${db.host}.
Property placeholders allow for much more powerful expressions.

           I find it even more elegant to embed this XML file directly into the application itself.
chandra s schrieb am Freitag, 18. Juli 2025 um 18:31:33 UTC+2:

Emmanuel Hugonnet

unread,
Jul 21, 2025, 2:39:38 AM7/21/25
to chandra s, WildFly
Another solution is to define your datasource(s) in a yaml file like this:


wildfly-configuration:
subsystem:
datasources:
jdbc-driver:
postgresql:
driver-name: postgresql
driver-xa-datasource-class-name: org.postgresql.xa.PGXADataSource
driver-module-name: org.postgresql.jdbc
data-source:
PostgreSQLDS:
enabled: true
exception-sorter-class-name: org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter
jndi-name: java:jboss/datasources/PostgreSQLDS
jta: true
max-pool-size: 20
min-pool-size: 0
connection-url: "jdbc:postgresql://localhost:5432}/demo"
driver-name: postgresql
user-name: postgres
password: postgres
validate-on-match: true
background-validation: false
background-validation-millis: 10000
flush-strategy: FailingConnectionOnly
statistics-enable: false
stale-connection-checker-class-name: org.jboss.jca.adapters.jdbc.extensions.novendor.NullStaleConnectionChecker
valid-connection-checker-class-name: org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker
transaction-isolation: TRANSACTION_READ_COMMITTED

and add it like define here [1].
Emmanuel

[1]: https://docs.wildfly.org/wildfly-proposals/core/WFCORE-5343_Support_YAML_files_for_configuration_customization.html

Le 19/07/2025 à 14:02, chandra s a écrit :
> Hi,
>
>   Thank you for responding. While executing CLI scripts modifies standalone.xml, I’m exploring a configuration approach that uses a
> separate XML file. The goal is for WildFly to automatically load updated parameters from this external source during startup and
> controlled by a separate file.
>
> On Friday, July 18, 2025 at 2:55:27 PM UTC-4 Wolfgang wrote:
>
> --
> You received this message because you are subscribed to the Google Groups "WildFly" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to wildfly+u...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/wildfly/939bd1ea-7862-4b1b-b43e-e81e17baaf58n%40googlegroups.com
> <https://groups.google.com/d/msgid/wildfly/939bd1ea-7862-4b1b-b43e-e81e17baaf58n%40googlegroups.com?utm_medium=email&utm_source=footer>.

Reply all
Reply to author
Forward
0 new messages