Saturday, October 6, 2018

Creating a MySQL Datasource in WildFly 14

To create a MySQL Datasource you first need te configure the MySQL driver, which doesn't come configured by default. To do this, I did the following. Remember to have the MySQL server running. At first don't start WildFly.

Firstly, follow this link to install the MySQL Driver in WildFly 14.

Secondly, you need to start WildFly 14 and access the localhost at port 9990: http://localhost:9990/.

Note that this will not work if you don't have a management user. If this URL gives you a WildFly text page with no management options, you most likely need to run the add-user.sh or add-user.bat in the bin directory of the WildFly installation, before proceeding.

Once you do that, you need to select the following option:



Then, a few dialogs will pop up, but in the end you need to have the following data. Please keep in mind that at some point you need to insert the username and the password you use to access the MySQL. You should also note the name of the database: proj2 in this case. For each different database you will need a different datasource. In the end you will have the opportunity to test the connection to the database. If it fails, check the output of WildFly.

Please mind the java:/MySqlDS JNDI name. This is the name that you must give in the persistence.xml file in the Java Persistence API project deployed in the same WildFly:

<jta-data-source>java:/MySqlDS</jta-data-source>