2016-04-30 04:39:32 +00:00
2021-11-10 11:39:43 +00:00
=== Packaging the JDBC driver
2016-04-27 21:01:22 +00:00
2021-11-10 11:39:43 +00:00
Find and download the JDBC driver JAR for your RDBMS. Before you can use this driver, you must package it up into a module and install it into the server. Modules define JARs that are loaded into the {project_name} classpath and the dependencies those JARs have on other modules.
2016-04-27 21:01:22 +00:00
2021-11-10 11:39:43 +00:00
.Procedure
2016-04-27 21:01:22 +00:00
2021-11-10 11:39:43 +00:00
. Create a directory structure to hold your module definition within the _.../modules/_ directory of your {project_name} distribution.
+
The convention is use the Java package name of the JDBC driver for the name of the directory structure. For PostgreSQL, create the directory _org/postgresql/main_.
2016-04-27 21:01:22 +00:00
2021-11-10 11:39:43 +00:00
. Copy your database driver JAR into this directory and create an empty _module.xml_ file within it too.
+
.Module Directory
image:{project_images}/db-module.png[Module Directory]
2016-04-27 21:01:22 +00:00
2021-11-10 11:39:43 +00:00
. Open up the _module.xml_ file and create the following XML:
+
2016-04-27 21:01:22 +00:00
.Module XML
[source,xml]
----
2021-11-10 08:52:24 +00:00
<?xml version="1.0" encoding="UTF-8"?>
2016-04-27 21:01:22 +00:00
<module xmlns="urn:jboss:module:1.3" name="org.postgresql">
<resources>
2021-11-10 07:58:57 +00:00
<resource-root path="postgresql-VERSION.jar"/>
2016-04-27 21:01:22 +00:00
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
----
2021-11-10 11:39:43 +00:00
+
* The module name should match the directory structure of your module. So, _org/postgresql_ maps to `org.postgresql`.
* The `resource-root path` attribute should specify the JAR filename of the driver.
* The rest are just the normal dependencies that any JDBC driver JAR would have.
=== Declaring and loading the JDBC driver
2016-04-27 21:01:22 +00:00
2021-11-10 11:39:43 +00:00
You declare your JDBC into your deployment profile so that it loads and becomes available when the server boots up.
2016-04-27 21:01:22 +00:00
2021-11-10 11:39:43 +00:00
.Prerequisites
2016-04-27 21:01:22 +00:00
2021-11-10 11:39:43 +00:00
You have packaged the JDBC driver.
2016-04-27 21:01:22 +00:00
2021-11-10 11:39:43 +00:00
.Procedure
2016-04-27 21:01:22 +00:00
2021-11-10 11:39:43 +00:00
. Declare your JDBC driver by editing one of these files based on your deployment mode:
2022-01-31 08:29:53 +00:00
* For standalone mode, edit _.../standalone/configuration/standalone.xml_.
* For standalone clustering mode, edit _.../standalone/configuration/standalone-ha.xml_.
2021-11-10 11:39:43 +00:00
* For domain mode, edit _.../domain/configuration/domain.xml_.
+
In domain mode, make sure you edit the profile you are using: either `auth-server-standalone` or `auth-server-clustered`
. Within the profile, search for the `drivers` XML block within the `datasources` subsystem.
+
You should see a pre-defined driver declared for the H2 JDBC driver. This is where you'll declare the JDBC driver for your external database.
+
2016-04-27 21:01:22 +00:00
.JDBC Drivers
2018-06-12 20:10:27 +00:00
[source,xml,subs="attributes+"]
2016-04-27 21:01:22 +00:00
----
2018-06-12 20:10:27 +00:00
<subsystem xmlns="{subsystem_datasources_xml_urn}">
2016-04-27 21:01:22 +00:00
<datasources>
...
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
----
2021-11-10 11:39:43 +00:00
. Within the `drivers` XML block, declare an additional JDBC driver.
2016-04-27 21:01:22 +00:00
2021-11-10 11:39:43 +00:00
* Assign any `name` to this driver.
* Specify the `module` attribute which points to the `module` package that you created earlier for the driver JAR.
* Specify the driver's Java class.
+
Here's an example of installing a PostgreSQL driver that lives in the module example defined earlier in this chapter.
+
2016-04-27 21:01:22 +00:00
.Declare Your JDBC Drivers
2018-06-12 20:10:27 +00:00
[source,xml,subs="attributes+"]
2016-04-27 21:01:22 +00:00
----
2018-06-12 20:10:27 +00:00
<subsystem xmlns="{subsystem_datasources_xml_urn}">
2016-04-27 21:01:22 +00:00
<datasources>
...
<drivers>
<driver name="postgresql" module="org.postgresql">
2017-01-10 06:16:29 +00:00
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
2016-04-27 21:01:22 +00:00
</driver>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
----
2017-03-27 16:49:29 +00:00