Setting up the basics of a Maven Java EE app on WildFly 18.0.1 with its MySQL database and database connector, and utilizing JPA Hibernate among other dependencies

Last Updated on: (senast uppdaterad på:)

A Java EE application should be designed with a structure that is easily understandable and makes a balanced use of Data Access Objects, Entities, REST controller, transactions and a database back end. To have the app hosted on WildFly 18.0.1 application server we would require a connection to the database on the server. Below are the basics for the preparation process in order to have a basic application run:


Set up a database. In our example, we set up a database called “WorkSuggest1” and set up a table within the database called “Person”:

create database WorkSuggest1;

 CREATE TABLE `person` (
  `name` varchar(255) ,
  `email` varchar(255) DEFAULT NULL,
  `phone` varchar(255) DEFAULT NULL,
  `address` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)


When the database is set up, start preparing the WildFly database connector and the data source that will be used in the application. A CLI script can be very useful to have this done. The script below (written by instructors at IT Högskolan Göteborg) helps to set up the module, given that you have the MySQL connector, so keep reading past the script below for more details. The link to the database is also needed. Be sure that the MySQL Connector is in c:\Users folder and the connector version is the one you have.

module add --name=com.mysql --resources=~/mysql-connector-java-8.0.19.jar --dependencies=javax.api,javax.transaction.api
data-source add --jndi-name=java:/worksuggest1 --name=worksuggest1 \
--connection-url="jdbc:mysql://localhost:3306/worksuggest1?allowPublicKeyRetrieval=true&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC" \
--driver-name=mysql --user-name=root --password=root --min-pool-size=2 --initial-pool-size=4 --max-pool-size=6
/subsystem=logging/file-handler=fh:add(level=INFO, file={"relative-to"=>"jboss.server.log.dir", "path"=>"worksuggest1.log"}, append=true, autoflush=true)

Normally, a MySQL connector is found in form of a Jar file such as the one found at, which will accompany a “module.xml” file.
To complete the set up, follow a good tutorial on how to set up MySQL database connection on WildFly application server, such as this one.

In general, be sure that you have the database connector, the required module file, and the link to the database set up correctly as they are required for your Java EE application to interact with the database. Some side notes while you are setting them up are:

  • The connector and the module.xml file should be placed in a directory structure that you create under the “base” folder hierarchy in the WildFly 18 folder structure — more specifically in the folder: C:\wildfly-18.0.1.Final\modules\system\layers\base. Here you will create a “com” folder, add a “mysql” folder there, and in it create a “main” folder. In this main folder you place the mysql connector file as well as the module.xml file.
  • The module.xml file could have content similar to the one below.
<module name="com.mysql" xmlns="urn:jboss:module:1.5">
        <resource-root path="mysql-connector-java-8.0.18.jar">
        <module name="javax.api">
        <module name="javax.transaction.api">


Continue the set up of the database for use via the application server. Given that you will use the CLI script above, place the CLI script in the bin folder of the WildFly 18.0.1 folder, go to the bin folder, and run the script while the server is running. Assuming you are using Windows PowerShell it would be:

.\jboss-cli -c --file=worksuggest1.cli


Upon receiving success message, proceed to setting up the IntelliJ project which should have a Maven.pom.xml file with dependencies as described in the below pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="" xmlns:xsi=""


  <name>worksuggest1 Maven Webapp</name>
  <description>Work Suggest Application</description>












    <!-- -->








The persistence.xml file can be as follows:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns:xsi=""
             version="2.0" xmlns="">
    <persistence-unit name="worksuggest1" transaction-type="JTA">
            <property name="hibernate.archive.autodetection" value="class, hbm" />
            <property name="" value="update" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL8Dialect" />
            <property name="hibernate.show_sql" value="true" />
            <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
            <property name="openjpa.Log" value="SQL=TRACE" />
            <property name="openjpa.ConnectionFactoryProperties" value="printParameters=true" />


A file structure such as the one shown below can help with the development of the project with respective Java EE concepts considered:


The complete and working project (given that the MySQL database is available and the WildFly 18.0.1 application server are running) is included in the zip file below.

Lämna ett svar