set a data source in jboss standalone mode - java

I want to set a mysql data source in jboss standalone mode. I have already deploy the mysql-connector-java-5.1.15-bin.jar and set the below data source configuration in standalone.xml under datasources
<datasource jndi-name="java:jboss/datasources/MySqlDS" pool-name="MySqlDS" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/testdb</connection-url>
<driver>mysql</driver>
<security>
<user-name>root</user-name>
</security>
</datasource>
And when i click on the configured data source name in the web console im getting below error,
Internal server error{
"outcome" => "failed",
"failure-description" => "JBAS014739: No handler for read resource at address [
(\"subsystem\"=>"\datasource\"),
(\"data-source\"=>"\MySqlDS\"),
(\"statstics\"=>"\pool\"),
"],
"roleback" => "true"
}
I didnt add any thing to the drivers section since it not nessaccary,
Below one is set to the sample data source set in jboss
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class
</driver>
</drivers>
What i am missing here please?

You will also need to specify driver class
<driver-class>com.mysql.jdbc.Driver</driver-class>
Checkout this link How do I migrate my application from AS5 or AS6 to AS7

I've experienced the same issue under the same circumstances. The problem was that my AS didn't have the required module for PostgreSQL. Check in jboss/modules/org if you have a folder named postgresql. If not then create it. Then create a directory in it named main.
You then have to have two files present in there:
PostgreSQL JDBC JAR
module.xml configuration file
Download the JAR file according to the database you're using and copy it here. As for the module.xml just create a new file and set up the configuration. Mine looks like this, customize it for your case:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.postgresql">
<resources>
<resource-root path="postgresql-9.3-1100.jdbc4.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
Basically you just have to change the resource path to where your JAR file is.
This is an issue with JBOSS, it doesn't warn you even though the JDBC driver is missing. I've wasted a ton of time finding this hidden bug :D

Related

Not able to create mysql datasource in Jboss 7.1.1

I am using jboss as 7.1.1 final release. I am trying to add mysql driver to the server via the admin console. I am able to do so but when I go to create the datasources, I do not find the driver listed there. I followed the steps to add the driver to the server as mentioned in this link :
http://www.appeon.com/support/documents/appeon_online_help/1.5/server_configuration_guide_for_j2ee/ch03s03s03.html#d0e4128
I followed from step 3 of Installing a JDBC driver via the Web console as I had already created one management user.To summarize what I did,
I added a driver file E:\DevSoftwares\servers\jboss\jboss-as-7.1.1.Final\modules\com\mysql\main\META-INF\services\java.sql.Driver and its content as following : com.mysql.jdbc.jdbc2.optional.MysqlXADataSource(fully qualified driver class name).
create module.xml file inside E:\DevSoftwares\servers\jboss\jboss-as-7.1.1.Final\modules\com\mysql\main\ and its content as below :
Added mysql-connector-java-5.0.8-bin.jar file inside E:\DevSoftwares\servers\jboss\jboss-as-7.1.1.Final\modules\com\mysql\main\
Ran jar -uf mysql-connector-java-5.0.8-bin.jar META-INF\services\java.sql.Driver command to modify the jar.
After running this command I could see a services\java.sql.Driver file with driver class name as given in step 1 inside META-INF folder of the jar file which was not there before running the command.
I picked up the fully qualified name of the driver class for mysql for Jboss 7.x from below link :
http://www.appeon.com/support/documents/appeon_online_help/1.5/server_configuration_guide_for_j2ee/ch03s03s07.html#d0e5769
I was able to figure out what is causing the problem, when I try to enable the deployed jar I get an exception in the server console stating : unable to instantiate driver class com.mysql.jdbc.jdbc2.optional.MysqlXADataSource :
java/lang.ClassCastException :
com.mysql.jdbc.jdbc2.optional.MysqlXADataSource.
However I checked the mysql-connector-java-5.0.8-bin.jar and was able to find the driver class mentioned above in the same directory structure as the classes fully qualified name.
I am not able to figure out why I am getting this exception or what I am doing wrong during the setup that is causing this issue.The platform I am using is windows. Could some one please help me with it.
NOTE : the content of module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.mysql">
<resources>
<resource-root path="mysql-connector-java-5.0.8-bin.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>`
Please check that you have added your MySQL datasource configuration in standalone.xml or in equivalent XML file:-
<subsystem xmlns="urn:jboss:domain:datasources:1.0">
<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>
<datasource jndi-name="java:jboss/datasources/MySqlExampleDS" pool-name="MySqlExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/jboss7db</connection-url>
<driver>mysql</driver>
<pool>
<max-pool-size>30</max-pool-size>
</pool>
<security>
<user-name>root</user-name>
<password>admin</password>
</security>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="mysql" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>

Wildfly 9 failing to load MySQL driver on startup

I am creating a web application for WildFly, which will connect to a MySQL database through JPA (Hibernate). For now, I am just trying to get WildFly to start up and load the MySQL driver in standalone mode. I am using this page as a guide: http://wildfly.org/news/2014/02/06/GlassFish-to-WildFly-migration/
I am running WildFly and MySQL locally on a Windows system:
Windows 7 Enterprise SP1
Oracle Java SE 1.8.0_45
WildFly 9.0.0.Final
MySQL Server 5.6
Attempts to use the recommended console commands did not succeed, so I have manually edited to WildFly configuration files to look like those in the examples on the page linked above. First, I created the module directory and placed in it the MySQL connector JAR and module.xml file:
Directory of C:\wildfly-9.0.0.Final\modules\system\layers\base\com\mysql\main
07/06/2015 09:54 AM <DIR> .
07/06/2015 09:54 AM <DIR> ..
07/06/2015 10:12 AM 334 module.xml
07/01/2015 02:38 PM 968,668 mysql-connector-java-5.1.35.jar
The above connector jar was copied from my local Maven repository, which Maven obtained through the following dependency:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.35</version>
</dependency>
The module.xml file was manually edited as follows, to resemble the example I found on wildfly.org:
<?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.35-bin.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
Finally, I added the driver and datasource to the datasources section of standalone.xml:
<datasource jndi-name="java:/MySQLDS" pool-name="MyDS" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/mydb</connection-url>
<driver>mysql</driver>
<security>
<user-name>root</user-name>
<password>secret</password>
</security>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="mysql" module="com.mysql">
<driver-class>com.mysql.jdbc.Driver</driver-class>
</driver>
</drivers>
Upon starting WildFly in standalone mode, by running %WILDFLY_HOME%\bin\standalone.bat, the following is the first error listed in %WILDFLY_HOME%\standalone\logs\server.log:
2015-07-06 10:25:47,321 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 33) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("jdbc-driver" => "mysql")
]) - failure description: "WFLYJCA0041: Failed to load module for driver [com.mysql]"
Similar issues that I have seen posted on Stack Overflow and other question/answer sites usually point to an oversight such as a typo in config files or a misnamed file. However, I've been over this over and over and cannot see any such mistake, and the same error has occurred even after upgrading from Java SE 7 and WildFly 8.2 and re-creating the configuration files from scratch. Any assistance would be greatly appreciated.
In my case it was a matter of having the wrong user:group for the directories and files under ../com/mysql/main
I changed it to wildlfy and everything worked as expected.
There was a typo in module.xml. The name of the connector JAR listed in module.xml did not match the actual JAR file in modules\system\layers\base\com\mysql\main.
In my case, it was an issue with double quotes. When I copied a WordPress sample of module.xml, I got (note the curly quotes):
<resource-root path=”postgresql-9.4.1211.jar”/>
... but Wildfly is very picky and needs this (straight quotes):
<resource-root path="postgresql-9.4.1211.jar"/>
In my case I have missed the main folder which module.xml and connector jar file need to be included.
Earlier it was
JBOSS_HOME\modules\system\layers\base\com\mysql\module.xml
and the correct path should be,(module.xml and jar needed be included inside of main)
JBOSS_HOME\modules\system\layers\base\com\mysql\main\module.xml
I know it has been while but that may help for others. The recommended approach is to deploy a driver is using the wildfly console (localhost:9990/console). once you deployed the driver jar then create your DS again by using the console then it will create it automatically in the standalone.xml. Sometimes, when doing those stuffs manually may cause missing tiny details which drive us crazy.
For me, it seems to be a coding problem. Before the tag
<module>
...
</module>
in my module.xml file, there is a mysterious blank, which is not utf-8 or English, causing my failure. After I deleted the blank or changed it to an English one. Everything is ok. Also, I looked for some solutions to this problem. Most of them can be summed to the module.xml file's problem. A name typo or the content coding. Hope it heplful for others.
Maybe two solutions for your issue:
You forgot the attribute slot on module element in module.xml file,
e.g.:
<?xml version="1.0" ?>
<module xmlns="urn:jboss:module:1.3" name="org.postgresql" slot="main">
<resources>
<resource-root path="postgresql-9.4.1212.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
add code slot="main" in module element, it will take effect.
If above approach doesn't work, it is considered with XML Module descriptors . The same issue with Wildfly Failed to Load Module for Oracle Driver:
Change the namespace version of module element in module.xml.
enjoy it.

Need help creating SQL Server datasource for JBoss EAP 6.1.0

I am working on a web service application on JBoss EAP 6.1.0, which requires a datasource for SQL Server 2008 to be created. I have downloaded and extracted the sqljdbc jar file, but am not sure where it goes on the application server. I tried referencing the EAP 6.1 configuration guide and a couple of other websites, but that did not help. I would be very grateful if someone could guide me with the steps to register the datasource on the application server.
It goes into your modules folder. You have have something like the following:
<JBOSS_HOME>\modules\com\microsoft\sqlserver\main
Your sqljdbc would be inside the folder structure above. You would also need to create a module.xml file in the same folder similar to:
<module xmlns="urn:jboss:module:1.1" name="com.microsoft.sqlserver">
<resources>
<resource-root path="sqljdbc4.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
Then finally in your standalone.xml, the datasources section should have a drivers definition that references your module as such:
<drivers>
<driver name="sqlserver" module="com.microsoft.sqlserver">
<xa-datasource-class>com.microsoft.sqlserver.jdbc.SQLServerXADataSource</xa-datasource-class>
</driver>
</drivers>
Hope that helps

JBoss datasource creation

JBoss creates datasource from *ds.xml files and I want to do this without such an xml file and still make JBoss provide datasources through jndi.
The code that I have written registers 4 mbeans :
RARDeployment at jboss.jca:service=ManagedConnectionFactory,name=" + dataSourceJndiUrl
JBossManagedConnectionPool at "jca:service=ManagedConnectionPool,name=" + dataSourceJndiUrl
TxConnectionManager at "jboss.jca:service=XATxCM,name=" + dataSourceJndiUrl
WrapperDataSourceService at "jboss.jca:service=DataSourceBinding,name=" + dataSourceJndiUrl
I would like to be able to retrieve a DataSource objects using the following code:
InitialContext ctx = null;
ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup(dataSourceJndiUrl);
Can someone tell me if the above is a correct approach and if yes what else needs to be done in order for it to work?
yes, is possible and is the best way to do it.
In my case, I needed to use an standalone-full configuration (EAP 6.2).
The first you need is the correct JDBC for your DB, for example I used the ojdbc6.jar. Copy this Jar into ${JBOSS_HOME}/modules/com/oracle/main/ . The JDBC must be with an module.xml, to make it valid for JBoss. To me, this was a correct configuration of the module.xml:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.oracle">
<resources>
<resource-root path="ojdbc6.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
Then, on the standalone-full.xml file you will find a tag with the urn of datasources, inside of that tag a datasources tag, and inside a drivers tag. You need to add this new JDBC, to me this was a succesfull configuration:
<drivers>
<driver name="Oracle" module="com.oracle">
<xa-datasource-class>com.oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
</driver>
</drivers>
Start the JBoss with that configuration and go to the Profile > Connector > Datasources. Add a new one with your own configuration (JNDI, User, Password, etc...), dont forget to add on properties the URL to your DB. Then, you will be able to use the JNDI for the DataSource.

New missing/unsatisfied dependencies: service jboss.jdbc-driver.com_mysql (missing) dependents: [service jboss.data-source.java:jboss/MyDB]

I am using JBoss 7.1.1. When I try to start the server, I get an exception. I have tried many solutions but nothing seems to work.
The following line appears in the logs -
New missing/unsatisfied dependencies:
service jboss.jdbc-driver.com_mysql (missing) dependents: [service jboss.data-source.java:jboss/MyDB]
Here is my standalone.xml:
</datasource>
<datasource jta="true" jndi-name="java:jboss/MyDB" pool-name="MyDB_Pool" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:mysql://localhost:3306/test</connection-url>
<driver>com.mysql</driver>
<security>
<user-name>root</user-name>
<password>root</password>
</security>
<timeout>
<idle-timeout-minutes>0</idle-timeout-minutes>
<query-timeout>600</query-timeout>
</timeout>
<statement>
<prepared-statement-cache-size>100</prepared-statement-cache-size>
<share-prepared-statements>true</share-prepared-statements>
</statement>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="com.mysql" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
This is my module.xml:
<?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.24-bin.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
<module name="javax.validation.api"/>
</dependencies>
</module>
But i still got this exception
Here is my web.xml(a part of it):
<resource-ref id="ResourceRef_1">
<res-ref-name>MyDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
<lookup-name>java:jboss/datasources/MyDB</lookup-name>
</resource-ref>
Can anyone help?
Your module.xml should be like this:
<module xmlns="urn:jboss:module:1.0" name="com.mysql" slot="main">
<resources>
<resource-root path="mysql-connector-java-5.1.24-bin.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>
And make sure you have mysql-connector-java-5.1.24-bin.jar and mysql-connector-java-5.1.24-bin.jar.index in same folder where you have module.xml.
Solved: New missing/unsatisfied dependencies: service jboss.jdbc-driver.com_ for Jboss / WildFly 10
Hi,
first stop the WildFly server.
then update standalone.xml file to add MS-SQL JTDS driver details and Datasource details like below:
<subsystem xmlns="urn:jboss:domain:datasources:4.0">
<datasources>
<datasource jta="true" jndi-name="java:/jdbc/speedtest-datasource" pool-name="MSSQLDSspeedTestDEV" enabled="true" use-ccm="true">
<connection-url>jdbc:jtds:sqlserver://serverName:1433;DatabaseName=dbName</connection-url>
<driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class>
<driver>JTDS</driver>
<security>
<user-name>username</user-name>
<password>password</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mssql.MSSQLValidConnectionChecker"/>
<background-validation>true</background-validation>
</validation>
</datasource>
<drivers>
<driver name="JTDS" module="net.sourceforge">
<driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class>
</driver>
</drivers>
</datasources>
</subsystem>
Module.xml for MS SQL JTDS: path : E:\Softwares\wildfly-10.1.0.Final\wildfly-10.1.0.Final\modules\system\layers\base\net\sourceforge\main ( need to create directory structure as highlighted and add module.xml and jtds-1.3.0.jar files).
(note in this example i have used module name as "net.sourceforge" and created the folder structure path as "net\sourceforge\main"). Please note this is more important to match the directory path and module name in module,xml file.
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="net.sourceforge">
<resources>
<resource-root path="jtds-1.3.0.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
Note: Please note that the path highlighted in green above at 2 places should match (ie directory structure and module name in module.xml),
For example. If you have created directory structure as E:\Softwares\wildfly-10.1.0.Final\wildfly-10.1.0.Final\modules\system\layers\base\net\sourceforge\jtds\main then module name in module.xml file should be “net.sourceforge.jtds” as shown below in module.xml file
Module.xml:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="net.sourceforge.jtds">
<resources>
<resource-root path="jtds-1.3.0.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
now save these two files and restart the wildFLY server.
Regards,
Rasool Javeed Mohammad
javeed.mca#gmail.com
try upgrading your mysql-connector. i was trying to deploy 5.1.5 (i was migrating from jboss 5.1 to 7.1.1 so i was just moving an already working environment over to the newer container). after banging my head against this for two days, i upgraded to 5.1.27 and the datasource deployed like a champ.
Try to delete META-INF/services/java.sql.Driver from the mysql connector lib.
One thing to check with this error is to make sure you are storing the data in the correct folder. For JBoss EAP 7.1, it is the modules\system\layers\base\com folder. Inside of the com folder, create an additional folder called mysql and a main folder inside of the mysql folder. The main folder will hold the jar file and the module.xml file.
Try below steps. i solve the same problem with you in wildfly8.0.0-final. if there occurs that duplicate mysql dependencies, remove configuration firstly, after restart your computer, try the steps again.
1. Create mysql folder
under: ${WILDFLY_HOME}/modules/system/layers/base
create the directories com/mysql/driver/main
copy the driver library jar Into the folder main
add module.xml
// urn:jboss:module:X.X should be same with the version of wildfly, you can reference other modules.
<module xmlns="urn:jboss:module:1.1" name="com.mysql.driver">
<resources>
<resource-root path="mysql-connector-java-5.1.16.jar" />
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
2. Register the module as driver with CLI.
${WILDFLY_HOME}/bin/standalone.sh (only if wildfly is not running)
./jboss-cli.sh
connect
/subsystem=datasources/jdbc-driver=mysql:add(driver-name=mysql,driver-module-name=com.mysql.driver,driver-class-name=com.mysql.jdbc.Driver)
If the operation is successful then the message below will be showed {"outcome" => "success"}
and into the file of the standalone profile the code below is produced
...
<driver name="mysql" module="com.mysql.driver">
<driver-class>com.mysql.jdbc.Driver</driver-class>
</driver>
3. Create database in mysql
login as root: mysql root -p
Create database
create tables
4. Create connection to database from console
http://localhost:9990/console
add datasources with configuration like
name: mysql
JNDI name: java:jboss/mysql
url: jdbc:mysql://localhost:3306/your_database
done.

Categories

Resources