Install MariaDB Java connector in JBOSS7
I have trouble to deploy EJBCA 6 on JBOSS7 with MariaDB. I have configured EJBCA to use JBOSS standalone. My configuration works when using the default H2 database backend. I have configured mariadb Java connector in the JBOSS standalone.xml
<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="mariadb" module="org.mariadb.jdbc">
<xa-datasource-class>org.mariadb.jdbc.MySQLDataSource</xa-datasource-class>
</driver>
</drivers>
<datasource jndi-name="java:/MariaDS" pool-name="MariaDS" enabled="false">
<connection-url>jdbc:mariadb://localhost:3306/ejbca</connection-url>
<driver>mariadb</driver>
<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
<pool>
<min-pool-size>100</min-pool-size>
<max-pool-size>200</max-pool-size>
</pool>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
<statement>
<prepared-statement-cache-size>100</prepared-statement-cache-size>
<share-prepared-statements/>
</statement>
</datasource>
</datasources>
and I have copied the MariaDB Java connector to JBOSS_HOME/modules/org/mariadb/jdbc/main/mariadb-java-client-1.1.5.jar and configured the module.xml like this:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="org.mariadb.jdbc">
<resources>
<resource-root path="mariadb-java-client-1.1.5.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
the MariaDB driver is listed in the boot.log and server.log. It is also listed via jboss-cli:
[standalone@localhost:9999 /] /subsystem=datasources:installed-drivers-list
{
"outcome" => "success",
"result" => [
{
"driver-name" => "mariadb",
"deployment-name" => undefined,
"driver-module-name" => "org.mariadb.jdbc",
"module-slot" => "main",
"driver-datasource-class-name" => "",
"driver-xa-datasource-class-name" => "org.mariadb.jdbc.MySQLDataSource",
"driver-class-name" => "org.mariadb.jdbc.Driver",
"driver-major-version" => 1,
"driver-minor-version" => 1,
"jdbc-compliant" => false
},
{
"driver-name" => "h2",
"deployment-name" => undefined,
"driver-module-name" => "com.h2database.h2",
"module-slot" => "main",
"driver-datasource-class-name" => "",
"driver-xa-datasource-class-name" => "org.h2.jdbcx.JdbcDataSource",
"driver-class-name" => "org.h2.Driver",
"driver-major-version" => 1,
"driver-minor-version" => 3,
"jdbc-compliant" => true
}
]
}
I have set the EJBCA database.properties like this:
database.driver=org.mariadb.jdbc.Driver
database.url=jdbc:mysql://hostname:3306/ejbca?characterEncoding=UTF
database.name=mysql
however when I try to deploy EJBCA to the JBOSS with ant deploy the deployment fails with:
jee:deployDSJBoss7:
[exec] Result: 1
[exec] Result: 1
[echo] data-source add --name=ejbcads --driver-name="org.mariadb.jdbc.Driver" --connection-url="jdbc:mysql://ejbca-test-05.vm:3306/ejbca?characterEncoding=UTF-8" --jndi-name="java:/EjbcaDS" --use-ccm=true --user-name="ejbca" --password="reverse" --validate-on-match=true --background-validation=false --prepared-statements-cache-size=50 --share-prepared-statements=true --min-pool-size=5 --max-pool-size=150 --pool-prefill=true --transaction-isolation=TRANSACTION_READ_COMMITTED --check-valid-connection-sql="select 1"
[exec] JBAS010468: Driver named "org.mariadb.jdbc.Driver" is not installed.
What am I doing wrong?
Refer to the below sample for module.xml. Update the jar file name with yours
<module xmlns="urn:jboss:module:1.1" name="org.mariadb">
<resources>
<resource-root path="mariadb-java-client-1.3.3.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
Refer to the below for Datasource config in standalone.xml or the xml you use. Replace IP/hostname, port no, database name(DB1), poolname, jndi-name as per what you need.
<datasource jndi-name="java:jboss/MariaDBDS" pool-name="MariaDBDS" enabled="true" statistics-enabled="true">
<connection-url>jdbc:mariadb://10.92.142.148:6603/DB1</connection-url>
<driver>mariadb</driver>
<new-connection-sql>SELECT 1</new-connection-sql>
<security>
<user-name>your-database-username</user-name>
<password>password</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>
<check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>
</validation>
</datasource>
Comeback to this part later and update your connection pool
Add below in drivers
<driver name="mariadb" module="org.mariadb">
<xa-datasource-class>org.mariadb.jdbc.MariaDbDataSource</xa-datasource-class>
</driver>
Start jboss and check datasources in the console and test connection