Adding a Datasource to JBoss EAP

15 minutes
  • 3 Learning Objectives

About this Hands-on Lab

The JBoss Enterprise Application Platform provides extensive support for deploying and managing Java-based applications. These applications often need supporting backends, such as databases. In this hands-on lab, we use a provided MySQL module to create a MySQL datasource for our applications to use.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Install and Configure MariaDB
  1. Install MariaDB:

    sudo yum install mariadb-server
  1. Ensure the MariaDB service has been started and set MariaDB to start at boot:

    sudo systemctl start mariadb
    sudo systemctl enable mariadb
  2. Secure the installation; there is no default password for root. Set a password, remove anonymous users, disallow remote root login, and remove the test database. Reload the privilege tables, following the prompt.

    sudo mysql_secure_installation
  3. Access the MySQL CLI as the root user, using the password you just provided:

    mysql -u root -p
  4. Create a new database, users; create the user jboss-eap and grant that user access to the database:

    create database users;
    grant all on users.* to 'jboss-eap' identified by 'pinehead';
  5. Log out of MySQL:

Add a Datasource
  1. Access the JBoss EAP CLI:

    cd /opt/jboss-eap
    sudo ./bin/
  1. Connect to the server:

  2. Register the MySQL driver:

  3. Create the datasource:

    data-source add --name=MySQLDS --jndi-name=java:/MySqlDS 
    --driver-name=mysql --connection-url=jdbc:mysql://localhost:3306/users 
    --user-name=jboss-eap --password=pinehead
Test the Connection

We can test the connection from the CLI with 1/subsystem=datasources/data-source=MySQLDS:test-connection-in-pool.

Additional Resources

You are setting up a new JBoss EAP standalone configuration to support a fledgling project for your team. The standalone server will support a number of small applications, each needing the ability to connect to a user MySQL database. You've already configured the global MySQL JDBC module, but still need to create the database itself and the datasource in JBoss EAP, including registering the com.mysql driver.

For the MySQL database, download MariaDB and create a user database that grants access to the jboss-eap MySQL user. Set a password for this user. This is the database we will use to test our connection.

The JBoss EAP home directory can be found at /opt/jboss-eap. To access the console, go to PUBLICIP:9990 and use the user admin and password pinehead.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?