0

我将 Apache Tomcat 10 与 Java JDK 16 一起使用,但在配置 Java 服务器端面时出现错误:

2021 年 9 月 24 日 13:57:24.063 严重 [http-nio-8080-exec-55] org.apache.catalina.core.StandardContext.loadOnStartup Servlet [Faces Servlet] 在 Web 应用程序 [/WebJsf] 中引发 load() 异常java.lang.ClassNotFoundException: com.sun.faces.util.Util

<code>
    <parent>
        <groupId>jakarta.platform</groupId>
        <artifactId>jakartaee-api-parent</artifactId>
        <version>9.1.0</version>
    </parent>

    <dependencies>
        
        <dependency>
            <groupId>jakarta.servlet</groupId>
            <artifactId>jakarta.servlet-api</artifactId>
            <version>${jakarta.servlet-api.version}</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>jakarta.servlet.jsp</groupId>
            <artifactId>jakarta.servlet.jsp-api</artifactId>
            <version>${jakarta.servlet.jsp-api.version}</version>
            <scope>compile</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>jakarta.el</groupId>
            <artifactId>jakarta.el-api</artifactId>
            <version>${jakarta.el-api.version}</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>jakarta.servlet.jsp.jstl</groupId>
            <artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
            <version>${jakarta.servlet.jsp.jstl-api.version}</version>
            <optional>true</optional> 
        </dependency> 
        
        <dependency>
            <groupId>jakarta.faces</groupId>
            <artifactId>jakarta.faces-api</artifactId>
            <version>${jakarta.faces-api.version}</version>
            <scope>compile</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>jakarta.ws.rs</groupId>
            <artifactId>jakarta.ws.rs-api</artifactId>
            <version>${jakarta.ws.rs-api.version}</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>jakarta.websocket</groupId>
            <artifactId>jakarta.websocket-api</artifactId>
            <version>${jakarta.websocket-api.version}</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>jakarta.json</groupId>
            <artifactId>jakarta.json-api</artifactId>
            <version>${jakarta.json-api.version}</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>jakarta.json.bind</groupId>
            <artifactId>jakarta.json.bind-api</artifactId>
            <version>${jakarta.json.bind-api.version}</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>jakarta.annotation</groupId>
            <artifactId>jakarta.annotation-api</artifactId>
            <version>${jakarta.annotation-api.version}</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>jakarta.ejb</groupId>
            <artifactId>jakarta.ejb-api</artifactId>
            <version>${jakarta.ejb-api.version}</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>jakarta.transaction</groupId>
            <artifactId>jakarta.transaction-api</artifactId>
            <version>${jakarta.transaction-api.version}</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>jakarta.persistence</groupId>
            <artifactId>jakarta.persistence-api</artifactId>
            <version>${jakarta.persistence-api.version}</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>jakarta.validation</groupId>
            <artifactId>jakarta.validation-api</artifactId>
            <version>${jakarta.validation-api.version}</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>jakarta.interceptor</groupId>
            <artifactId>jakarta.interceptor-api</artifactId>
            <version>${jakarta.interceptor-api.version}</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>jakarta.enterprise</groupId>
            <artifactId>jakarta.enterprise.cdi-api</artifactId>
            <version>${jakarta.enterprise.cdi-api.version}</version>
            <optional>true</optional>
            <exclusions>
              <exclusion>
                  <groupId>jakarta.inject</groupId>
                  <artifactId>jakarta.inject-api</artifactId>
              </exclusion>
          </exclusions>
        </dependency>
        <dependency>
            <groupId>jakarta.inject</groupId>
            <artifactId>jakarta.inject-api</artifactId>
            <version>${jakarta.inject.version}</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>jakarta.authentication</groupId>
            <artifactId>jakarta.authentication-api</artifactId>
            <version>${jakarta.authentication-api.version}</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>jakarta.security.enterprise</groupId>
            <artifactId>jakarta.security.enterprise-api</artifactId>
            <version>${jakarta.security.enterprise-api.version}</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>jakarta.xml.bind</groupId>
            <artifactId>jakarta.xml.bind-api</artifactId>
            <version>${jakarta.xml.bind-api.version}</version>
        </dependency>

        <!-- work around for GLASSFISH-19861  -->         
         
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>jakarta.faces</artifactId>
           <version>4.0.0-M1</version> 
                <!--  <version>${mojarra.version}</version> -->
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>jakarta.json</artifactId>
            <version>2.0.1</version>
        </dependency>
        
        <!-- ********************************* -->
        <dependency>
            <groupId>jakarta.security.auth.message</groupId>
            <artifactId>jakarta.security.auth.message-api</artifactId>
            <version>2.0.0-RC1</version>
            <scope>compile</scope>
        </dependency>
        
        <dependency>
            <groupId>org.glassfish.web</groupId>
            <artifactId>jakarta.servlet.jsp.jstl</artifactId>
            <version>2.0.0-M1</version>
        </dependency> 
        <dependency>
            <groupId>jakarta.platform</groupId>
            <artifactId>jakarta.jakartaee-api</artifactId>
            <version>9.1.0</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>jakarta.xml.ws</groupId>
            <artifactId>jakarta.xml.ws-api</artifactId>
            <version>4.0.0-RC1</version>
        </dependency>
 
        <!-- https://mvnrepository.com/artifact/org.primefaces/primefaces -->
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>10.0.0</version>
            <classifier>jakarta</classifier>
        </dependency>
        <!-- https://mvnrepository.com/artifact/jakarta.xml.bind/jakarta.xml.bind-api-test -->
        <dependency>
            <groupId>jakarta.xml.bind</groupId>
            <artifactId>jakarta.xml.bind-api-test</artifactId>
            <version>3.0.1</version>
        </dependency>
        <!--
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <version>3.0.2</version>
        </dependency>-->
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>3.0.2</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.activation</groupId>
            <artifactId>jakarta.activation-api</artifactId>
            <version>2.1.0-RC1</version>
        </dependency>
   </dependencies>
</code>
4

1 回答 1

0

如果您声明一个可选依赖项(参见文档),Maven 不会将其打包到 WAR 文件(或任何其他工件)中。因此org.glassfish:jakarta.faces不会与您的 WAR 文件捆绑在一起。

因此,您应该使用:

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>jakarta.faces</artifactId>
    <version>4.0.0-M1</version>
</dependency>

(即删除<optional>true</optional>)。

于 2021-09-29T18:47:33.817 回答