This tutorial builds a small Jakarta Faces 4.1 web application from scratch with Maven, WildFly and H2. It starts with a "Hello World" form and ends with a form which saves messages in a database and lists them in a table. It does not need an IDE. Every step is a file to create or a command to run. Any text editor will do, and so will an AI coding agent such as Claude Code.
The tutorial uses Java 25, Maven 3.10, WildFly 42 and Faces 4.1, which is part of Jakarta EE 11. Looking for JSF 2.3 with javax.* packages instead? Then head to the JSF 2.3 tutorial with Eclipse, Maven, WildFly and H2.
Installing Java SE JDK
Download and install a Java SE 25 JDK, for example Eclipse Temurin. Make sure the java command is in the PATH and the JAVA_HOME environment variable points to the JDK folder. Verify it as follows:
java -version
It should print a version starting with 25. Java 21 works as well; then use 21 in the pom.xml further on.
Installing Maven
Download the binary zip of Apache Maven 3.10 and unzip it somewhere. Add its bin folder to the PATH. Verify it as follows:
mvn -v
It should print the Maven version and the Java version it runs on. That Java version must be the JDK you just installed.
Installing WildFly
Download the zip of WildFly 42 and unzip it somewhere. That is all. In this tutorial its folder is referred to as /path/to/wildfly. Start it as follows:
/path/to/wildfly/bin/standalone.sh
On Windows it is standalone.bat. Once the log says WildFly 42.0.1.Final and started, open http://localhost:8080 in the browser. It shows the welcome page of WildFly. Leave it running. Press Ctrl+C in the terminal to stop it.
What about Jakarta EE?
First a small bit of history. Oracle handed Java EE over to the Eclipse Foundation, where it was renamed to Jakarta EE in 2018. The first release, Jakarta EE 8 in 2019, was still the same as Java EE 8, with the same javax.* packages. Jakarta EE 9 in 2020 renamed all javax.* packages to jakarta.*. Jakarta EE 10 in 2022 came with Faces 4.0, and Jakarta EE 11 in 2025 came with Faces 4.1. So anything you find on the internet about "Java EE" or "JSF" with javax.faces.* imports is outdated. The ideas mostly still apply, but the code does not run on a current server as is.
Jakarta Faces itself is part of Jakarta EE. Jakarta EE is basically an abstract specification, and the so-called application servers are the concrete implementations of it. Examples are Eclipse GlassFish, Open Liberty, Payara Server, TomEE and WildFly. You can find them all at the Jakarta EE Compatible Products page. It are exactly those application servers which provide among others Faces, EL (Expression Language), CDI (Contexts and Dependency Injection), JPA (Jakarta Persistence), Bean Validation, Transactions, REST, Servlet and WebSocket out of the box. WildFly 42 for example ships Mojarra 4.1 as its Faces implementation, Weld as its CDI implementation and Hibernate as its JPA implementation.
There also exist so-called servlet containers which provide basically only Servlet, Pages (formerly JSP), EL and WebSocket out of the box, such as Tomcat and Jetty. On those you would need to manually install and configure among others Faces, CDI, JPA and Bean Validation yourself. That is not trivial, and that is exactly why TomEE exists: it is Tomcat with the missing Jakarta EE parts already installed. This tutorial uses WildFly, so all of this is already there.
Your web application therefore does not need to bundle any of those libraries. It only needs the Jakarta EE API to compile against. That is the jakarta.jakartaee-api dependency, with the provided scope, so it does not end up in the WAR file. The server provides the actual implementation at runtime. You do not need to add implementation libraries such as Mojarra, Weld or Hibernate to the pom.xml yourself. The server has its own.
Creating the project
Create a folder named project with the following Maven-compatible structure. The files are filled in the next sections.
project
├── pom.xml
└── src
└── main
├── java
│ └── com
│ └── example
│ └── Hello.java
└── webapp
├── WEB-INF
│ ├── faces-config.xml
│ └── web.xml
└── hello.xhtml
Here is the pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>project</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<maven.compiler.release>25</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>11.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
</build>
</project>
The jakarta.jakartaee-api dependency is the whole Jakarta EE 11 API. The finalName makes sure the WAR file is named project.war instead of the Maven default project-1.0-SNAPSHOT.war, so the context path of the application becomes /project.
Configuring Faces
Faces activates itself when the web application contains a /WEB-INF/faces-config.xml file. Without it, the server serves hello.xhtml as a plain static file, with all the Faces tags unprocessed. An empty one is enough:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-facesconfig_4_1.xsd"
version="4.1">
</faces-config>
A CDI bean annotated with @FacesConfig activates Faces as well. Sooner or later you need the faces-config.xml anyway, for example for resource bundles, a custom exception handler factory or the locale configuration, which cannot be configured by annotations. So you can as well start with it.
The FacesServlet is the Controller part of MVC: it takes the request, finds the Facelets file belonging to the URL, and builds the HTML response from it. A beans.xml is not needed either. CDI discovers by default all classes which are annotated with a CDI scope, such as @RequestScoped, @ViewScoped and @ApplicationScoped.
Faces has a lot of settings which can be configured via <context-param> entries in web.xml. You can find an overview of them, along with the Mojarra-specific ones, in CONTEXT-PARAMS.md of Mojarra. The defaults are okay to start with, but there is one peculiar setting which you really want to set right from the beginning on. It is the setting which instructs Faces to interpret empty string submitted values as null. Without it, an empty input field ends up as an empty string in the bean property, and then in the database. Elaborate background information can be found in The empty String madness.
Faces also automatically maps its FacesServlet on four URL patterns: *.xhtml, /faces/*, *.faces and *.jsf. So the same page is reachable by four different URLs, such as /hello.xhtml, /faces/hello.xhtml, /hello.faces and /hello.jsf. That is not good for search engines, which see four copies of the same page. The *.xhtml pattern is the only one you need, because it is the same as the file extension of the Facelets files. When you register the FacesServlet yourself with only that pattern, the other three are not activated anymore. Create the /WEB-INF/web.xml file with both:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_1.xsd"
version="6.1">
<context-param>
<param-name>jakarta.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>
<servlet>
<servlet-name>facesServlet</servlet-name>
<servlet-class>jakarta.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>facesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>
Creating the backing bean
With the project now correctly configured you can finally start with developing the actual MVC application. The Controller part is already there: it is the FacesServlet. The Model part is what you are going to create now. It is basically just a simple Java class, which is by Faces convention called a backing bean, since it "backs" a view. Here is the com.example.Hello class:
package com.example;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Named;
@Named
@RequestScoped
public class Hello {
private String input;
private String output;
public void submit() {
output = "Hello World! You have typed: " + input;
}
public String getInput() {
return input;
}
public void setInput(String input) {
this.input = input;
}
public String getOutput() {
return output;
}
}
It has two properties, input and output. The input property has a getter and a setter, because the view needs to set it with the submitted value and get it to redisplay it. The output property has only a getter, because the view only needs to display it. The submit() method is the action method which prepares the output based on the input, and which the view invokes on submit. We will briefly go through the annotations which are used here.
@Named: gives the bean a name, which is primarily used to reference it via EL in the view. Without any attributes this name defaults to the simple class name with the first letter in lowercase, thushellohere. It is available by#{hello}in EL. In older tutorials you will find@ManagedBeanfrom thejavax.faces.beanpackage in this place. CDI is preferred over it since Java EE 6, and the whole package was removed in Faces 4.0.@RequestScoped: gives the bean a scope, which means that the same instance of the bean is used throughout the given lifespan. In the case of@RequestScopedthat lifespan is the duration of a single HTTP request. When the scope ends, the bean is automatically destroyed. There are more scopes available, such as@ViewScoped,@SessionScopedand@ApplicationScoped. You can read more about them in "Bean scopes" of the Communication in JSF and Faces article.
Creating the Facelets file
Next, you create the View part of MVC. It is basically just an XHTML file, which is by Faces interpreted as a Facelets file, or just "Facelet". When the FacesServlet is invoked with a URL matching the path of this Facelets file, Faces parses it and generates the HTML markup which is sent to the browser. With help of EL, it can reference a bean property and invoke a bean action. Here is the hello.xhtml file, in the src/main/webapp folder:
<!DOCTYPE html>
<html lang="en"
xmlns:f="jakarta.faces.core"
xmlns:h="jakarta.faces.html">
<h:head>
<title>Hello World</title>
</h:head>
<h:body>
<h1>Hello World</h1>
<h:form id="form">
<h:outputLabel for="input" value="Input" />
<h:inputText id="input" value="#{hello.input}" label="Input" required="true" />
<h:commandButton id="submit" value="Submit" action="#{hello.submit}">
<f:ajax execute="@form" render="@form" />
</h:commandButton>
<h:message id="message" for="input" />
<h:outputText id="output" value="#{hello.output}" />
</h:form>
</h:body>
</html>
The jakarta.faces.core and jakarta.faces.html namespaces declare the Faces tag libraries, with the f: and h: prefixes. These short URNs were introduced in Faces 4.0. Previously they were URLs, such as http://xmlns.jcp.org/jsf/html in JSF 2.2 and 2.3, and http://java.sun.com/jsf/html before that. Those confused starters, who took them for real web addresses which the browser or the server would download something from. They are just unique identifiers; nothing is ever downloaded from them. We will briefly go through the Faces tags which are used here.
<h:head>: generates the HTML<head>element. It gives Faces the opportunity to automatically include any necessary JavaScript files, such as thefaces.jscontaining the logic for<f:ajax>.<h:body>: generates the HTML<body>element. It gives Faces the opportunity to include JavaScript at the end of the body as well.<h:form>: generates the HTML<form method="post">element. Faces automatically includes the so-called view state in a hidden input field within the form. All inputs and buttons must be inside an<h:form>.<h:outputLabel>: generates the HTML<label>element. You could also use a plain HTML<label>, but then you have to figure out yourself the actual ID of the target input element as it ends up in the HTML. Faces prefixes it with the ID of the form, so it becomesform:input. Theforattribute of<h:outputLabel>takes care of that.<h:inputText>: generates the HTML<input type="text">element. Faces automatically gets and sets the value in the bean property specified in thevalueattribute. Therequired="true"makes Faces show a validation message when the input is empty. In that case the bean property is not set and the action method is not invoked. Thelabelis the name of the field in that message.<h:commandButton>: generates the HTML<input type="submit">element. Faces automatically invokes the bean method specified in theactionattribute.<f:ajax>: adds ajax behavior to the tag it is nested in, in this case the<h:commandButton>. You can also do without it, but then the whole page reloads on submit. Theexecuteattribute of@formindicates that the entire<h:form>must be processed on submit, and therenderattribute of@formindicates that it must be updated once the ajax submit completes. You can read more about it in "Ajax POST form" of the Communication in JSF and Faces article.<h:message>: generates an HTML<span>element with the validation message of the input specified in theforattribute, if any.<h:outputText>: generates an HTML<span>element. It merely prints the bean property specified in thevalueattribute. The<span>is only rendered when it has anidor a style attribute.
Those Faces tags are also called "Faces components". Note that you can perfectly mix plain vanilla HTML in a Facelets file, such as the <h1> here. Faces components should only be used when the functionality requires so. Also note that the HTML5 doctype is used even though it is an XHTML file. The XHTML is only the source format: Facelets requires the file to be well-formed XML, but the browser gets plain HTML5.
Deploying the project
Open a terminal in the project folder, build the WAR file and copy it to the standalone/deployments folder of WildFly:
mvn clean package cp target/project.war /path/to/wildfly/standalone/deployments
On Windows it is copy with backslashes instead of cp. The WAR file is only a few kilobytes, because all of Jakarta EE is provided by the server. WildFly watches the standalone/deployments folder and deploys the WAR file within a few seconds. Once its log says Deployed "project.war", open http://localhost:8080/project/hello.xhtml in the browser. Type something in the input field and press the Submit button. The text appears next to the button. Press the button with an empty input field, and a validation message appears instead.
After every change in the project, run the same two commands again. WildFly redeploys the WAR file as soon as you copy a new one over it. WildFly also deploys all WAR files in that folder on startup.
Coming back to the URL, the localhost:8080 part is the default address of WildFly on your own machine. The /project part is by default the file name of the WAR file, without the extension. This part is in Servlet terms called the "context path". It is obtainable by HttpServletRequest#getContextPath(), and in Faces by ExternalContext#getRequestContextPath(). When in doubt, you can find it in the server log, in the line identified by WFLYUT0021:
WFLYUT0021: Registered web context: '/project' for server 'default-server'
The context path can also be set to /, so the web application ends up in the domain root. How to do that depends on the server. In case of WildFly, you need to create the WildFly-specific /WEB-INF/jboss-web.xml file as follows:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web xmlns="urn:jboss:jakartaee:1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:jboss:jakartaee:1.0 https://www.jboss.org/schema/jbossas/jboss-web_15_1.xsd"
version="15.1">
<context-root>/</context-root>
</jboss-web>
After building and copying the WAR file again, the page is available at http://localhost:8080/hello.xhtml. You can even go a step further by making hello.xhtml the default landing file, so that it does not need to be specified in the URL either. Add the following entry to the bottom of the web.xml, just before </web-app>:
<welcome-file-list>
<welcome-file>hello.xhtml</welcome-file>
</welcome-file-list>
This instructs the server to serve the specified file when a folder is requested. So when the / folder is requested, it serves /hello.xhtml. After building and copying the WAR file again, the page is also available at merely http://localhost:8080. The rest of this tutorial however keeps using http://localhost:8080/project/hello.xhtml, so leave these two changes out if you want to follow along literally.
Configuring JPA
Next step is to save the input in a database. Jakarta EE prescribes that every server provides a default datasource. WildFly maps it to its built-in H2 database, which lives in memory. You do not need to install H2 nor to configure a datasource. A persistence unit without a datasource uses the default one. Create the src/main/resources/META-INF/persistence.xml file, along with its folders:
<?xml version="1.0" encoding="UTF-8"?>
<persistence
xmlns="https://jakarta.ee/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_2.xsd"
version="3.2">
<persistence-unit name="project">
<properties>
<property name="jakarta.persistence.schema-generation.database.action" value="drop-and-create" />
</properties>
</persistence-unit>
</persistence>
The persistence unit is the configuration of JPA. Its name is free to choose. Because it does not specify a transaction-type, it defaults to JTA in a Jakarta EE server. This basically means that the server manages the database transactions for you. You will see that in action in "Creating the service".
The drop-and-create action generates the database tables from the JPA entities on every deploy. This is, of course, only useful for prototyping, as you are basically doing in this tutorial. The in-memory database is empty after every restart of the server anyway.
Creating the JPA entity
Now you are going to create a JPA entity. Basically, it is a JavaBean class which represents a single record of a database table. Each property is mapped to a column of the table. Normally, JPA entities are modeled against existing database tables. But, as you have read in "Configuring JPA", it is also possible to do it the other way round: the database tables are generated based on the JPA entities. Here is the com.example.Message class:
package com.example;
import java.time.Instant;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
@Entity
public class Message {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false)
private String text;
@Column(nullable = false)
private Instant created;
public Long getId() {
return id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public Instant getCreated() {
return created;
}
public void setCreated(Instant created) {
this.created = created;
}
}
We will briefly go through the annotations which are used here.
@Entity: marks the class as a JPA entity, mapped to a database table with the same name,message. The JPA implementation automatically collects the database metadata from all its properties.@Id: marks the property as the primary key of the table.@GeneratedValue(strategy = GenerationType.IDENTITY): lets the database generate the value of the primary key when the record is inserted. You never set it yourself. JPA reads it back after the insert. In MySQL terms, that is the equivalent ofAUTO_INCREMENT. In PostgreSQL terms, that is the equivalent ofBIGSERIAL.@Column: maps the property to a regular database column. Thenullable = falsegenerates aNOT NULLconstraint. The column type depends on the Java type: aStringbecomes aVARCHAR(255), whose length can be changed by@Column(length = n), and anInstantbecomes aTIMESTAMP WITH TIME ZONE.
The id property has only a getter, because only JPA sets it.
Creating the service
Next, you need a service class to save a Message in the database, and to get a list of them from the database. Here is the com.example.MessageService class:
package com.example;
import java.time.Instant;
import java.util.List;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import jakarta.transaction.Transactional;
@ApplicationScoped
public class MessageService {
@PersistenceContext
private EntityManager entityManager;
@Transactional
public void create(Message message) {
message.setCreated(Instant.now());
entityManager.persist(message);
}
public List<Message> list() {
return entityManager.createQuery("FROM Message m ORDER BY m.id DESC", Message.class).getResultList();
}
}
That is basically it. We will briefly go through the annotations.
@ApplicationScoped: makes the class a CDI bean of which only one instance exists in the entire application. It is shared by all requests. This is fine as long as the class does not hold any changing state of its own, as is the case here.@PersistenceContext: injects the JPA entity manager of the persistence unit in thepersistence.xml. The entity manager is responsible for mapping all JPA entities against the database. It does all the hard JDBC work under the covers. The injected instance is a proxy which is safe to share between requests.@Transactional: starts a database transaction when the method is invoked, and commits it when the method returns. When the method throws a runtime exception, the transaction is rolled back instead. Reading does not need a transaction.
The FROM Message m ORDER BY m.id DESC is a JPQL query. It looks like SQL, but it works on the entity class and its properties instead of on the table and its columns. In older tutorials you will find an EJB with @Stateless in this place. A CDI bean with @Transactional does the same job. The @Transactional annotation exists since Java EE 7, but CDI can substitute everything else a @Stateless EJB does only since Jakarta EE 10, when Jakarta Concurrency 3.0 brought an @Asynchronous annotation for CDI beans. Since then CDI is preferred over EJB. See also How to migrate from EJB to CDI?
Adjusting the backing bean and Facelet
Change the com.example.Hello class as follows:
package com.example;
import java.io.Serializable;
import java.util.List;
import jakarta.annotation.PostConstruct;
import jakarta.faces.view.ViewScoped;
import jakarta.inject.Inject;
import jakarta.inject.Named;
@Named
@ViewScoped
public class Hello implements Serializable {
private Message message = new Message();
private List<Message> messages;
@Inject
private MessageService messageService;
@PostConstruct
public void init() {
messages = messageService.list();
}
public void submit() {
messageService.create(message);
messages.add(0, message);
message = new Message();
}
public Message getMessage() {
return message;
}
public List<Message> getMessages() {
return messages;
}
}
We will briefly go through the changes.
@ViewScoped: the bean now lives as long as you interact with the same page by ajax. A@RequestScopedbean would load the list of messages from the database again on every single ajax request. Note that it is the one from thejakarta.faces.viewpackage.Serializable: is required for a@ViewScopedbean, because the server may save it in the HTTP session.@Inject: injects theMessageServicebean.@PostConstruct: marks the method which runs right after the bean is constructed and all its dependencies are injected. The injectedmessageServiceis not yet available in the constructor, which is why the list is loaded in theinit()method.
The submit() method saves the new message, adds it to the top of the list, and creates a new empty one for the form. Note that the message and messages properties do not need setters. The view uses the getters and setters of the Message entity itself.
And change the hello.xhtml file as follows:
<!DOCTYPE html>
<html lang="en"
xmlns:f="jakarta.faces.core"
xmlns:h="jakarta.faces.html">
<h:head>
<title>Hello World</title>
</h:head>
<h:body>
<h1>Hello World</h1>
<h:form id="form">
<h:outputLabel for="input" value="Input" />
<h:inputText id="input" value="#{hello.message.text}" label="Input" required="true" />
<h:commandButton id="submit" value="Submit" action="#{hello.submit}">
<f:ajax execute="@form" render="@form :messages" />
</h:commandButton>
<h:message id="message" for="input" />
</h:form>
<h:dataTable id="messages" value="#{hello.messages}" var="message">
<h:column>#{message.id}</h:column>
<h:column>#{message.text}</h:column>
<h:column>#{message.created}</h:column>
</h:dataTable>
</h:body>
</html>
The input field is now bound to the text property of the Message entity. The <f:ajax> now also renders the <h:dataTable>. The :messages refers to it by its ID, with a leading colon because the table is outside the form. You can read more about this syntax in "Rendering outside the form" of the Communication in JSF and Faces article.
The <h:dataTable> generates an HTML <table> with a row for every item of the list specified in the value attribute. The var attribute gives the current item a name, so you can reference it in EL as #{message}. Every <h:column> generates a cell in the row. Inside it you can just put EL in the template text. You do not need an <h:outputText> for that. Much more about tables, such as an action per row, editing rows and sorting, can be found in Using datatables in JSF and Faces.
Build and copy the WAR file again, and refresh the page. Every message you submit now appears at the top of the table. Open the page in another browser tab, and you see that the messages are really in the database.
Switching to PostgreSQL
The in-memory H2 database is not meant for production, of course. Here is how to switch to PostgreSQL. It assumes a PostgreSQL database named project with a user yourusername and password yourpassword.
First download the PostgreSQL JDBC driver and copy it to the /path/to/wildfly/standalone/deployments folder, next to the WAR file. WildFly recognizes it as a JDBC driver and registers it by its file name. Then create a configure-postgresql.cli file in the root of the project, next to the pom.xml:
# Configures the PostgreSQL datasource of the project.
/subsystem=datasources/data-source=ProjectDS:add( \
jndi-name="java:jboss/datasources/ProjectDS", \
driver-name="postgresql-42.7.15.jar", \
connection-url="jdbc:postgresql://localhost:5432/project", \
user-name="yourusername", \
password="yourpassword" \
)
While WildFly is running, open a terminal in the root of the project and run it with the WildFly command line interface:
/path/to/wildfly/bin/jboss-cli.sh --connect --file=configure-postgresql.cli
On Windows it is jboss-cli.bat. WildFly saves the datasource in its standalone/configuration/standalone.xml, so you need to run this only once per server. The script however lives in the project, so you can run it again on the next server. Do not commit the real password in it, of course. Then reference it by its JNDI name in the persistence.xml, and remove the drop-and-create property, or the tables are dropped on every deploy:
<?xml version="1.0" encoding="UTF-8"?>
<persistence
xmlns="https://jakarta.ee/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_2.xsd"
version="3.2">
<persistence-unit name="project">
<jta-data-source>java:jboss/datasources/ProjectDS</jta-data-source>
</persistence-unit>
</persistence>
Without the drop-and-create property, JPA does not create the tables anymore. So create them yourself in the project database:
CREATE TABLE message (
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
text VARCHAR(255) NOT NULL,
created TIMESTAMP WITH TIME ZONE NOT NULL
);
Finally build the WAR file again and copy it over the old one. The messages now survive a restart of WildFly.
