Reputation: 2566
I've got following error when I want to start Wildfly server:
09:26:10,548 WARN [org.jboss.modules.define] (MSC service thread 1-1) Failed to define class jakarta.faces.webapp.FacesServlet in Module "deployment.demo-0.0.1-SNAPSHOT.war" from Service Module Loader: java.lang.NoClassDefFoundError: Failed to link...
But after I change (in web.xml file):
<servlet-class>jakarta.faces.webapp.FacesServlet</servlet-class>
to
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
the error is gone.
I've tried it with both version 4.0.0 and 3.0.0 of jakarta.faces-api dependency:
<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>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/jakarta.faces/jakarta.faces-api -->
<dependency>
<groupId>jakarta.faces</groupId>
<artifactId>jakarta.faces-api</artifactId>
<version>4.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
</plugin>
</plugins>
</build>
</project>
And here is my web.xml file:
<?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_5_0.xsd"
version="5.0">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>jakarta.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>
Based on jakarta.ee/specifications/faces/3.0 and jakarta.ee/specifications/faces/4.0 I can use jakarta.faces.webapp.FacesServlet class, So why I got the error?
I'm using latest Eclipse (Version: 2022-03 (4.23.0)) and wildfly-26.1.0.Final.
Upvotes: 3
Views: 5941
Reputation: 1109422
According to the WildFly download page, wildfly-26.1.0.Final
is not a Jakarta EE 9 server, let alone a Jakarta EE 10 server. It's a Jakarta EE 8 server.
Jakarta EE 8 in turn ships with JSF 2.3 (and Servlet 4.0).
This means that you should be using javax.faces.*
package and the faces-config.xml
should be conform JSF 2.3 and web.xml
should be conform Servlet 4.0.
You most probably intended to pick the wildfly-preview-26.1.0.Final
download link, provided by the section above of it, specifically labeled as Preview. This one is a Jakarta EE 9 server which is the first one with Jakartified package names (i.e. jakarta.*
instead of javax.*
) and ships with JSF 3.0 (and Servlet 5.0). The Jakarta EE 10 implementation will be provided by the upcoming WildFly 27.x, currently still in Alpha stage. It's going to provide Faces 4.0 (and Servlet 6.0).
That said, your pom.xml
is incorrect for a full fledged Jakarta EE server. You should never manually ship loose Jakarta EE artifacts such as JSF along with the webapp. You should declare the entire Jakarta EE dependency as provided
instead of the individual JSF dependency as a physical JAR file enclosed in the WAR. Below one is for Jakarta EE 8:
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>8.0.0</version>
<scope>provided</scope>
</dependency>
That's really all you need in pom.xml
.
Upvotes: 6