Skip to main content

How to configure a Datasource in JBoss / WildFly as a JAR Deployment


JDBC drivers can be installed as a JAR deployment using either the management CLI or the management console. As long as the driver is JDBC 4-compliant, it will automatically be recognized and installed as a JDBC driver upon deployment.
1. Download the appropriate JDBC driver from your database vendor.
2. Start the JBoss EAP/WildFly server.
3. Now most of the drivers coming with JDBC 4-compliant, but in case If the JDBC driver JAR is not JDBC 4-compliant, it can be made deployable using the following steps.
i) Create a directory structure META-INF/services on your local system.

$ mkdir -p META-INF/services
  
ii) Create a file inside META-INF/services/java.sql.Driver.


$ touch META-INF/services/java.sql.Driver
 
iii) Add one line in the file to indicate the fully-qualified class name of the JDBC driver.

$ echo “com.mysql.jdbc.Driver” > META-INF/services/java.sql.Driver

iv) Use the JAR command-line tool to add this new file to the JAR.


$ jar \-uf mysql-connector-java-5.1.47-bin.jar META-INF/services/java.sql.Driver
   
v) Now this JAR is ready to deploy.

 
4. Deploy the JAR to JBoss EAP. There is two way to deployment – either you can direct copy the JAR file into the deployment directory where your standalone is running or you can do it from jboss console.

[standalone@localhost:9990 ]deploy /tmp/mysql-connector-java-5.1.47-bin.jar
5. After successful deployment, you can see below output in your EAP logs.

12:45:25,335 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-2) WFLYJCA0019: Stopped Driver service with driver-name = mysql
12:48:00,927 INFO [org.jboss.as.repository] (DeploymentScanner-threads - 1) WFLYDR0001: Content added at location /opt/wildfly-11.0.0.Final/standalone/data/content/63/e2cbc99a452e2696852918a30c5a8ade104ce1/content
12:48:00,939 INFO [org.jboss.as.server.deployment] (MSC service thread 1-2) WFLYSRV0027: Starting deployment of "mysql-connector-java-5.1.47-bin.jar" (runtime-name: "mysql-connector-java-5.1.47-bin.jar")
12:48:01,219 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-1) WFLYJCA0005: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
12:48:01,220 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-1) WFLYJCA0005: Deploying non-JDBC-compliant driver class com.mysql.fabric.jdbc.FabricMySQLDriver (version 5.1)
12:48:01,233 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-1) WFLYJCA0018: Started Driver service with driver-name = mysql-connector-java-5.1.47-bin.jar_com.mysql.jdbc.Driver_5_1
12:48:01,234 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-1) WFLYJCA0018: Started Driver service with driver-name = mysql-connector-java-5.1.47-bin.jar_com.mysql.fabric.jdbc.FabricMySQLDriver_5_1
12:48:01,359 INFO [org.infinispan.factories.GlobalComponentRegistry] (MSC service thread 1-2) ISPN000128: Infinispan version: Infinispan 'Chakra' 8.2.8.Final
12:48:01,565 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 62) WFLYCLINF0002: Started client-mappings cache from ejb container
12:48:01,617 INFO [org.jboss.as.server] (DeploymentScanner-threads - 1) WFLYSRV0010: Deployed "mysql-connector-java-5.1.47-bin.jar" (runtime-name : "mysql-connector-java-5.1.47-bin.jar")

6. You can see “driver-name = mysql-connector-java-5.1.47-bin.jar_com.mysql.jdbc.Driver_5_1” in the EAP logs, that’s our JDBC driver.

12:48:01,233 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-1) WFLYJCA0018: Started Driver service with driver-name = mysql-connector-java-5.1.47-bin.jar_com.mysql.jdbc.Driver_5_1

7. We have deployed the mysql driver in EAP_HOME/standalone/deployments and Now add the datasource connection.
Syntax :- /subsystem=datasources/data-source=<DATASOURCE_NAME>:add(jndi-name=java:/<JNDI_NAME>, driver-name=<DRIVER_NAME>, connection-url="jdbc:mysql://<DATABASE_SERVER_NAME>:<DB_PORT>/<DATABASE_NAME>", user-name=<DB_USER>, password=<DB_PASSWORD>)


[standalone@localhost:9990 /] /subsystem=datasources/data-source=mysql_jndi:add(jndi-name=java:/mysql_jndi, driver-name=mysql-connector-java-5.1.47-bin.jar_com.mysql.jdbc.Driver_5_1, connection-url="jdbc:mysql://192.168.122.165:3306/JBTRAVEL", user-name=JBTRAVEL, password=JBTRAVEL)

8. Now you can see the datasource connection added into the standalone.xml file.

<datasource jndi-name="java:/mysql_jndi" pool-name="mysql_jndi">
<connection-url>jdbc:mysql://192.168.122.165:3306/JBTRAVEL</connection-url>
<driver>mysql-connector-java-5.1.47-bin.jar_com.mysql.jdbc.Driver_5_1</driver>
<security>
<user-name>JBTRAVEL</user-name>
<password>JBTRAVEL</password>
</security>
</datasource>

9. Now test the datasource connection.
Syntax :- /subsystem=datasources/data-source=<DATASOURCE_NAME>:test-connection-in-pool

[standalone@localhost:9990 /] /subsystem=datasources/data-source=mysql_jndi:test-connection-in-pool



Comments

  1. I truly appreciate the time and work you put into sharing your knowledge. I found this topic to be quite effective and beneficial to me. Thank you very much for sharing. Continue to blog.

    Data Engineering Services 

    Artificial Intelligence Solutions

    Data Analytics Solutions

    Data Modernization Solutions

    ReplyDelete
  2. I truly appreciate the time and work you put into sharing your knowledge. I found this topic to be quite effective and beneficial to me. Thank you very much for sharing. Continue to blog.

    Data Engineering Services 

    AI & ML Solutions

    Data Analytics Services

    Data Modernization Services

    ReplyDelete
  3. I appreciate you taking the time and effort to share your knowledge. This material proved to be really efficient and beneficial to me. Thank you very much for providing this information. Continue to write your blog.

    Data Engineering Services 

    Artificial Intelligence Solutions

    Data Analytics Services

    Data Modernization Solutions

    ReplyDelete

Post a Comment

Popular posts from this blog

Shift your Data into Virtualization

A single approach to data management that allows an application or user to retrieve and manipulate data without knowing any technical details about the data. That approach called Data Virtualization. Data Virtualization is different than traditional virtualization like - VMWare, Hypervisor, KVM, etc. because we already learned how to do virtualization of OS, Hardware and Storage, now time to add some more into virtualization, which is DATA. What is Data Virtualization? Data virtualization is a single window used to describe any approach to data management that allows an application to retrieve and manipulate data without requiring technical details about the data, such as how it is formatted, or where it is physically located. Why use Data Virtualization? Data virtualization promotes efficiency in data usage and processing and accelerates time to market on projects with complex data storage infrastructure. The purpose is to allow data to be accessed without creating extra ...

How to Install JBOSS EAP 7.0.0 on RHEL6.5/CentOS6.5 – a step by step tutorial of INSTALLER Installation

INTRODUCTION In this tutorial, we will demonstrate how to install and start a JBoss EAP 7.0.0 server on RHEL 6.5/CentOS 6.5. We use Oracle JDK 8 for this tutorial. This Tutorial Consists Of The Following Steps: Step 1: Download installer link Step 2: JDK installation and verification Step 3 to Step 14: JBoss EAP 7 installation procedure using INSTALLER Installation Step 15: Start Jboss EAP 7 server Red Hat JBoss EAP 7.0 is based on Wildfly 10 , and provides pre-configured options for features such as high-availability clustering, messaging, and distributed caching. And it is an application server that works as a middleware platform, is built on open standards, and is compliant with the Java EE 7 specification. Step 1: Download the installer from: https://developers.redhat.com/products/eap/download/ Select the EAP 7.0.0 (Developers version) from the list. Click on Installer option within Download column. For Linux/ Windows/Mac...