Ram
Ram

Reputation: 41

Jakarta Faces 4 - Netbeans 18 - 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.

enter image description here

Web.xml:

<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_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:

org.apache.catalina.core.StandardWrapperValve.invoke Allocate exception for servlet [facesServlet]
    java.lang.ClassNotFoundException: com.sun.faces.util.Util

Upvotes: 1

Views: 64

Answers (1)

BalusC
BalusC

Reputation: 1109412

java.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 forgot 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:

Do note that the jakarta.faces.4.0.x.jar is the API+impl merged into single JAR. And please don't forget 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:

Upvotes: 2

Related Questions