I'm in the process of setting up a brand new JavaServer Faces project that uses Jakarta without maven using netbeans IED 18, Tomcat 10.1.31, Java 11. and while I understand the problem with the stacktrace, I can't understand why (the new) Jakarta Faces implementation is asking me for an old dependency.
Web.xml:
<web-app
xmlns=
xmlns:xsi=
xsi:schemaLocation= .xsd
version="6.0"
>
<servlet>
<servlet-name>facesServlet</servlet-name>
<servlet-class>jakarta.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>facesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<param-name>jakarta.faces.AUTOMATIC_EXTENSIONLESS_MAPPING</param-name>
<param-value>true</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
Bean Class:
package com.example;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Named;
@Named
@RequestScoped
public class Hello {
private String name;
private String message;
public void createMessage() {
message = "Hello, " + name + "!";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMessage() {
return message;
}
}
Error:
.apache.catalina.core.StandardWrapperValve.invoke Allocate exception for servlet [facesServlet]
java.lang.ClassNotFoundException: com.sun.faces.util.Util
I'm in the process of setting up a brand new JavaServer Faces project that uses Jakarta without maven using netbeans IED 18, Tomcat 10.1.31, Java 11. and while I understand the problem with the stacktrace, I can't understand why (the new) Jakarta Faces implementation is asking me for an old dependency.
Web.xml:
<web-app
xmlns=https://jakarta.ee/xml/ns/jakartaee
xmlns:xsi=http://www.w3./2001/XMLSchema-instance
xsi:schemaLocation=https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd
version="6.0"
>
<servlet>
<servlet-name>facesServlet</servlet-name>
<servlet-class>jakarta.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>facesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<param-name>jakarta.faces.AUTOMATIC_EXTENSIONLESS_MAPPING</param-name>
<param-value>true</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
Bean Class:
package com.example;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Named;
@Named
@RequestScoped
public class Hello {
private String name;
private String message;
public void createMessage() {
message = "Hello, " + name + "!";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMessage() {
return message;
}
}
Error:
.apache.catalina.core.StandardWrapperValve.invoke Allocate exception for servlet [facesServlet]
java.lang.ClassNotFoundException: com.sun.faces.util.Util
Share
Improve this question
edited 17 hours ago
BalusC
1.1m376 gold badges3.6k silver badges3.6k bronze badges
asked 20 hours ago
RamRam
412 bronze badges
1 Answer
Reset to default 1java.lang.ClassNotFoundException: com.sun.faces.util.Util
That's not an "old dependency". That's actually part of the Faces impl. This exception is literally hinting you that your app is searching for the Faces impl but couldn't find it anywhere. You indeed fot to install it. The jakarta.faces-api JAR you have there is apparently from Mojarra, which is the Faces impl using com.sun.faces package. Tomcat is not a full Jakarta EE server. It's basically only provides JSP/Servlet/EL/Websocket/JASPIC API+impls out the box. So you need to manually install all the other things Jakarta EE not provided by Tomcat, such as JSF, JSTL, CDI, Validation, etc.
So far, you installed the following things:
- Jakarta Faces API (but not impl!) via jakarta.faces-api
- Jakarta CDI API and impl via weld-servlet-shaded
- Jakarta Tags API (but not impl!) via jakarta.servlet.jsp.jstl-api
- Jakarta Connectors API (but not impl!) via jakarta.resource-api
These don't match the Tomcat installation instructions of Mojarra (one of the available JSF implementations, the one using com.sun.faces
package). You can find it in the README of the Mojarra 4.0 branch. Below is an extract of your interest, please carefully follow it:
Non-Maven
In case you're manually carrying around JARs:
Jakarta EE containers (WildFly, JBoss EAP, TomEE, Payara, GlassFish, Liberty, etc)
You don't need to add any JARs to
/WEB-INF/lib
!Jakarta Servlet containers (Tomcat, Jetty, etc)
Add below JARs to
/WEB-INF/lib
:
jakarta.faces.4.0.x.jar
weld-servlet-shaded-4.0.x.Final.jar
jakarta.servlet.jsp.jstl-api-2.0.x.jar
jakarta.json-api-2.0.x.jar
(optional, only when<f:websocket>
is used)jakarta.json-2.0.x.jar
(optional, only when<f:websocket>
is used)validation-api-3.0.x.Final.jar
(optional, only when<f:validateBean|validateWholeBean>
is used)hibernate-validator-8.0.x.Final.jar
(optional, only when<f:validateBean|validateWholeBean>
is used)Substitute
x
with latest version number available.
Do note that the jakarta.faces.4.0.x.jar
is the API+impl merged into single JAR. And please don't fet to remove all the current JARs which are not listed above, such as the jakarta.faces-api. Else you may still run into conflicts caused by duplicate classes in the runtime classpath.
See also:
- What exactly is Java EE?
- How to properly configure Jakarta EE libraries in Maven pom.xml for Tomcat?
- How to properly install and configure JSF libraries via Maven?