How to install JDBC driver to JBoss EAP 6 / WildFly 8
On JBoss EAP 6 / WildFly 8, you have two ways of installing the JDBC driver:
- deploy it as any other application package
- install it as a module
Deploy the driver as application package is recommend when you have a cluster environment, since the deployments are automatically propagated in the server groups.
See also:
See also:
How to add Datasource to JBoss EAP 6 / WildFly 8
Deploying the JDBC Driver
When the JDBC driver is installed as a deployment, it is deployed as a regular JAR. If the JBoss EAP 6 / Wildfly instance is running as a standalone server, copy the JDBC 4.0 compliant JAR into the Application_server_HOME/standalone/deployments/ directory. For a managed domain, you must use the Management Console or Management CLI to deploy the JAR to the server groups.
The following is an example of a MySQL JDBC driver installed as a deployment to a standalone server:
$cp mysql-connector-java-5.1.33-bin.jar Application_server_HOME/standalone/deployments/
You can deploy from the admin console too. Go to Runtime > Server > Manage Deployments and click on Add to deploy the JDBC driver. Upload the driver and give a new name to it. Any JDBC4-compliant driver is automatically recognised by WildFly and made available for new datasources. If not using a JDBC4 driver, then click on En/Disable right after the deployment.
Creating a Module
You may have issues with the deployment if the driver is not JDBC4-compliant. In this case, installing the driver as a module solves those issues. The advantage of the JDBC driver as a module is the possibility of creating a custom WildFly bundle for your organization. This way, you can repeat exactly the same installation throughout several machines, preserving the same configuration. This is perfect for the development environment.
To create a module (use MySQL as example):
- Unzip the downloaded file and copy the file mysql-connector-java-5.1.33-bin.jar to the new folder (create the subfolder as needed) WILDFLY_HOME/modules/system/layers/base/com/mysql/main
- create the file module.xml in the same folder with the following content:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.mysql">
<resources>
<resource-root path="mysql-connector-java-5.1.33-bin.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
<module xmlns="urn:jboss:module:1.1" name="com.mysql">
<resources>
<resource-root path="mysql-connector-java-5.1.33-bin.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
The name of the driver file may vary, so make sure you declare exactly the same name in the resource-root tag. At this point, the module is not available yet. We still need to reference the module as a driver in WildFly configuration. Do it using the following command:
[standalone@localhost:9990 /] /subsystem=datasources/jdbc-driver=mysql:add(
driver-name=mysql,
driver-module-name=com.mysql,
driver-class-name=com.mysql.jdbc.Driver
)
driver-name=mysql,
driver-module-name=com.mysql,
driver-class-name=com.mysql.jdbc.Driver
)
The command returns {"outcome" => "success"} in case of success. This command resulted in the following part in the configuration file:
<datasources>
{...}
<drivers>
{...}
<driver name="mysql" module="com.mysql">
<driver-class>com.mysql.jdbc.Driver</driver-class>
</driver>
</drivers>
</datasources>
{...}
<drivers>
{...}
<driver name="mysql" module="com.mysql">
<driver-class>com.mysql.jdbc.Driver</driver-class>
</driver>
</drivers>
</datasources>
It makes the JDBC driver module available for the datasource creation.
Comments
Post a Comment