wildfly - installing postgres driver jar - jdbc

I am having difficulty installing the postgres driver. I've tried a bunch of things:
https://docs.jboss.org/author/display/WFLY10/Application+deployment
a. tried "deploying" the JAR (both from CLI and admin console UI)
https://sites.google.com/site/jmdstips/jboss-wildfly/postgresql-on-wildfly---xa-datasource
a. tried putting module definition in modules/org/postgresql ...
b. tried putting module definition in modules/system/layers/base/org/postgresql
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="org.postgres">
<resources>
<resource-root path="postgresql-9.4.1212.jre7.jar" />
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
And:
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="postgresql" module="org.postgresql">
<datasource-class>org.postgresql.Driver</datasource-class>
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
</drivers>
After all of that, I get this error. So, I think wildfly can "see" the module, but something is awry.
23:24:15,889 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 33) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("jdbc-driver" => "postgresql")
]) - failure description: "WFLYJCA0041: Failed to load module for driver [org.postgresql]"

short answer: put the driver in the /wildfly/standalone/deployments folder, it will deploy the driver automatically

It turns out I used "org.postgres" for the module name in standalone.xml instead of "org.postgresql" which is what I declared it as inside the module.xml

I also encountered this error and it was due to the module.xml not having the correct resource-root

Related

Whats the correct way to allow different jdbc drivers for deployed applications on JBoss / Wildfly?

My setting is the following:
I got an application, which I deploy in /standalone/deployments
The jboss-deployment-structure.xml of my deployment in /standalone/deployments looks the following:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
[...]
<module name="org.postgresql"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
To drop the jboss-deployment-structure.xml completely (because it must not be used if there are no classloading issues), doesn't work. I use more dependencies (keycloak) beside the driver, which can't be found then.
My module.xml in my module org/postgresql/main looks like this (like described in https://www.keycloak.org/docs/4.8/server_installation/index.html#package-the-jdbc-driver)
<?xml version="1.0" encoding="UTF-8"?>
<module name="org.postgresql" xmlns="urn:jboss:module:1.5">
<resources>
<resource-root path="postgresql-42.2.5.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
My requirement is, to allow different types of jdbc-drivers, e.g. postgres, oracle, mssql.
First option:
I can change my jboss-deployment-structure.xml to
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
[...]
<module name="org.postgresql" optional="TRUE"/>
<module name="com.oracle.ojdbc6" optional="TRUE"/>
[...]
</dependencies>
</deployment>
</jboss-deployment-structure>
(added the optional-parameter)
Then I have to allow all drivers explicitly. Seems to be not the best way.
The idea comes from the standard documentation.
Second option:
I change my module-path to driver/jdbc/main (instead of org/postgres/main) and the module.xml to
<module name="driver.jdbc" xmlns="urn:jboss:module:1.5">
[...]
</module>
(changed name of module)
and go with the module-reference in my jboss-deployment-structure.xml like
<jboss-deployment-structure>
[...]
<module name="driver.jdbc"/>
[...]
</jboss-deployment-structure>
Now I force my customers to name the driver-module like I proposed. They can't name the module like mentioned in every standard-documentation.
The idea comes from this question.
I am doing this in context of a keycloak installation with a self-implemented User-federation to access a separate (legacy) user-database. Therefore dropping the jboss-deployment-structure.xml is no option as mentioned above.
Whats the correct way to achieve my goal of being flexible with the jdbc-driver?
EDIT: mentioned, dropping jboss-deployment-structure.xml is not working.
Keycloak have a very well designed container. You can get inspiration from it for your deployment. Just take a look at how the Dockerfile installs database driver modules and later how to activate those modules using jboss_cli.
Of course, if you can, maybe you can use the container instead. Just make sure to include the module.xml for your driver and activate it on start-up by providing your own entrypoint.
I would suggest you should install all database drivers individually as modules. Individual modules will help you to track and upgrade driver jars easily in the future.
As long as you don't have any classloading problems with your application you don't need to mention these drivers in the jboss-deployment-structure.xml file. They are static modules and will be loaded on server startup.
Moreover, after installing the driver modules, you have to add entries in the standalone.xml file. For example, if I have installed Oracle driver then
<driver name="oracle" module="com.oracle">
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
</driver>
within the tag.
Add a datasource definition within the tag (next to ExampleDS):
<datasource jndi-name="java:/[NAME]" pool-name="OracleDS" enabled="true">
<connection-url>jdbc:oracle:thin:#[HOST_NAME]:1521:[SID]</connection-url>
<driver>oracle[has to match the driver name]</driver>
<pool>
<min-pool-size>1</min-pool-size>
<max-pool-size>5</max-pool-size>
<prefill>true</prefill>
</pool>
<security>
<user-name>[USER]</user-name>
<password>[PWD]</password>
</security>
</datasource>
At least I went with a hybrid solution of my two above mentioned approaches for the jboss-deployment-structure.xml like as follows
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.postgresql" optional="TRUE"/>
<module name="com.oracle.ojdbc6" optional="TRUE"/>
[...]
<module name="driver.jdbc" optional="TRUE"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
I listed all the relevant database divers as optional modules and listed another one with flexible naming if a driver is desired, which is not mentioned in the list above.

Wildfly 10 Final postgres driver ClassCastException

eventually somebody can help me. Currently I have a really strange problem when starting wildfly 10 Final with a postgres driver but with the same setting wildfly 10 CR4 will start up.
The exception I get is following:
Caused by: javax.resource.ResourceException: IJ031089: Failed to load datasource: org.postgresql.Driver
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getDataSource(LocalManagedConnectionFactory.java:650)
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:311)
... 6 more
Caused by: java.lang.ClassCastException: org.postgresql.Driver cannot be cast to javax.sql.DataSource
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getDataSource(LocalManagedConnectionFactory.java:633)
... 7 more
The strange thing is, it works on wildfly 10 CR4 but not on the final version wildfly 10 Final. Any Idea?
For me it looks like a class loader problem but I'm not that an expert with wildfly to track it down.
my modules/org/postgres/main/module.xml:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.postgres">
<resources>
<resource-root path="postgresql-9.4.1208.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
My driver definition in standalone.xml
<driver name="postgres" module="org.postgres">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
<datasource-class>org.postgresql.Driver</datasource-class>
</driver>
Java JDK is: jdk1.8.0_73
Would really appreciate any help to fix my problem.
Thx in advance
/david
The class name implementing a DataSource is either:
org.postgresql.ds.PGSimpleDataSource
or
org.postgresql.ds.PGPoolingDataSource
https://jdbc.postgresql.org/documentation/head/ds-ds.html
I assume Wildfly will manage the connections, so you probably don't need the pooling DataSource, only the simple:
So it should be
<driver name="postgres" module="org.postgres">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
<datasource-class>org.postgresql.ds.PGSimpleDataSource</datasource-class>
</driver>

Wildfly Failed to Load Module for Oracle Driver

I'm attempting to add an Oracle DB datasource to Wildfly 10. Here's what I have:
<wildfly-home>\modules\com\oracle\ojdbc6\main\
module.xml
ojdbc6.jar
module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:Wildfly:module:1.0" name="com.oracle.ojdbc6">
<resources>
<resource-root path="ojdbc6.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.resource.api"/>
<module name="javax.transaction.api"/> <!-- See * below -->
</dependencies>
</module>
* I have tried both with and without the line <module name="javax.transaction.api/>. Some examples I've found online include it. Some do not. It seems to make no difference with whether the error occurs or not.
ojdbc6.jar was copied from <oracle-home>\jdbc\lib\ojdbc6.jar.
I have modified <wildfly-home>\standalone\configuration\standalone.xml to include this within the <drivers> tag:
<driver name="oraclethin" module="com.oracle.ojdbc6">
<xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
</driver>
This error message is being spat out when I cd into <wildfly-home>\bin and run .\standalone.bat:
15:17:13,415 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 33) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("jdbc-driver" => "oraclethin")
]) - failure description: "WFLYJCA0041: Failed to load module for driver [com.oracle.ojdbc6]"
I've triple checked the spelling on everything. I've tried taking out some lines (and putting them back when nothing changes). Is anyone seeing what I'm missing?
Use xmlns="urn:jboss:module:1.0"
As described in https://docs.jboss.org/author/display/MODULES/Module+descriptors
what solve the issue for me was to enlarge the timeout connection on the standalone.xml file on jboss
<system-properties>
...
<property name="jboss.as.management.blocking.timeout" value="6000"/>
</system-properties>

Db2 Driver/Datasource setup on wildfly: Failed to load module for driver [com.ibm]

I am wanting to configure the data source for db2 on my wildfly server (Wildfly.8.0.0-Final and 8.1.0 as well.) and am running into some problems doing so.
My research tells me this is a two step process
install the drivers as a module in the %JBOSS_HOME%/modules/com/ibm/main dir.
configure the datasources subsystem to include this module as a driver in your connection settings.
So far I have installed the module under the following structure with the following module.xml:
modules/
`-- com/
`-- ibm/
`-- main/
|-- db2jcc4.jar
|-- db2jcc_license_cu.jar
|-- db2jcc_license_cisuz.jar
`-- module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="com.ibm">
<resources>
<resource-root path="db2jcc4.jar"/>
<resource-root path="db2jcc_license_cu.jar"/>
<resource-root path="db2jcc_license_cisuz.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="sun.jdk"/>
</dependencies>
</module>
There is no space before the <?...?> in the xml file. the module name is "com.ibm" and the datasource is as follows:
<subsystem xmlns="urn:jboss:domain:datasources:2.0">
<datasources>
<datasource jndi-name="java:/jdbc/MyDS" pool-name="MyDS" enabled="true" use-java-context="true">
<xa-datasource-property name="ServerName">myIP</xa-datasource-property>
<xa-datasource-property name="PortNumber">1234</xa-datasource-property>
<xa-datasource-property name="DatabaseName">MyDB</xa-datasource-property>
<xa-datasource-property name="DriverType">4</xa-datasource-property>
<driver>ibmdb2</driver>
<pool>
<min-pool-size>0</min-pool-size>
<max-pool-size>50</max-pool-size>
</pool>
<security>
<user-name>bob</user-name>
<password>isyouruncle</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.db2.DB2ValidConnectionChecker"/>
<stale-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.db2.DB2StaleConnectionChecker"/>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.db2.DB2ExceptionSorter"/>
</validation>
</datasource>
<drivers>
<driver name="ibmdb2" module="com.ibm">
<xa-datasource-class>com.ibm.db2.jcc.DB2XADatasource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
The loading up of the server produces this error:
12:49:01,228 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 9) JBAS014613: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("jdbc-driver" => "ibmdb2")
]) - failure description: "JBAS010441: Failed to load module for driver [com.ibm]"
Which in turn causes my datasource declaration to fail loading as the driver is missing.
I am using older documentation as a guide because there doesn't seem to be any available for wildfly as yet. this documentation shows some promise but it seems a little out of date. If anyone has had any experience setting this up then Your help would be much appreciated.
I want to connect to DB2 9.7.
Please and thank you.
try replacing :
<resources-root path="db2jcc4.jar"/>
<resources-root path="db2jcc_license_cu.jar"/>
<resources-root path="db2jcc_license_cisuz.jar"/>
by
<resource-root path="db2jcc4.jar"/>
<resource-root path="db2jcc_license_cu.jar"/>
<resource-root path="db2jcc_license_cisuz.jar"/>
Remove the s from resources-route!
You could try to enable jboss.jdbc.spy = TRACE and add spy="true" to the datasource.
<datasource jndi-name="..." ... spy="true">
and
<logger category="jboss.jdbc.spy">
<level name="TRACE"/>
</logger>
This is normally to debug the JDBC, but perhaps it shows more on the loading of the driver as well.
Also you definitely need the resource-root without s.
I had the same issue. I resolved it by removing these two lines from module.xml:
<resource-root path="db2jcc_license_cu.jar"/>
<resource-root path="db2jcc_license_cisuz.jar"/>
I don't have a specific explanation as to why this worked.
This is not the solution to your problem but a reference for future visitors who (like me) come to this question by search of the same error message:
Today I had the same problem, for me it was an error in module.xml and standalone-full.xml. In both cases the module name was given as com.ibm.main, but it should have been com.ibm.
So in short: If you encounter this message and double checking the config files doesn't help, rewrite them.
jar files in module main folder should be added to the module.xml as
<resources>
<resource-root path="db2jcc4.jar"/>
<resource-root path="db2jcc_license_cu.jar"/>
</resources>
If you're using db2jcc.jar and not db2jcc4.jar and as you're defining a standard (non-XA) datasource, perhaps it helps to spedicfy the driver class too.
<driver-class>com.ibm.db2.jcc.DB2Driver</driver-class>
Everything is correct, just make s capital for (DB2XADatasource) as below:
<xa-datasource-class>com.ibm.db2.jcc.DB2XADataSource</xa-datasource-class>

JDBC Postgresql driver on JBoss 7

Deploying Postgresql JDBC into JBoss 7.1.1 Final as a module according to the instructions given in How to connect Jboss-as-7.1.1 with Postgresql .
Created the path $JBOSS_HOME/modules/org/postgresql/main
In $JBOSS_HOME/modules/org/postgresql/main/modules.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.postgresql">
<resources>
<resource-root path="postgresql-9.2-1002.jdbc4.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
Into the same directory placed postgresql-9.2-1002.jdbc4.jar
Opened jboss-cli by running $JBOSS_HOME/bin/jboss-cli --connect and ran the command:
/subsystem=datasources/jdbc-driver=postgresql-driver:add(driver-name=postgresql-driver, driver-class-name=org.postgresql.Driver, driver-module-name=org.postgresql)
After it got this error:
Failed to get the list of the operation properties: "JBAS010850: No
handler for operation read-operation-description at address [
("subsystem" => "datasources"),
("jdbc-driver" => "postgresql-driver") ]"
Try to define profile where you want to append a driver. This command appends a new driver in the full profile:
/profile=full/subsystem=datasources/jdbc-driver=postgresql-driver:add(driver-name=postgresql-driver, driver-class-name=org.postgresql.Driver, driver-module-name=org.postgresql)

Resources