How to connect to a DataSource from a remote client?

WildFly and JBoss EAP 6/7 no longer support remote JNDI lookup of datasource objects. If you attempt to lookup a Datasource object from a remote client, the following error will be thrown:

ERROR: org.jboss.remoting3.MessageCancelledException
Exception in thread "main" org.jboss.naming.remote.protocol.NamingIOException: Failed to lookup [Root exception is org.jboss.jca.core.connectionmanager.pool.strategy.OnePool]

As an alternative, it is recommend using an EJB as facade in accessing the data source, and defining a proper contract for how the data should be accessed and managed.

JBoss 5 users

If you are running JBoss As 5 this option is still available, although discouraged. To allow it, you need to tell JBoss NOT to bind the Datasource under the “java:/”
As a matter of fact this restricts the lookup to the same VM as the JBoss server.

Simply use’ tag <use-java-context>false</use-java-context> in your -ds.xml file

This is a sample Datasource file for mysql configured to accept remote client access