JakartaSever Faces 应用程序设置失败 java.lang.ClassNotFoundException:com.sun.faces.util.Util

JakartaSever Faces application setup fails with java.lang.ClassNotFoundException: com.sun.faces.util.Util

我正在建立一个使用 Jakarta 的全新 JavaServer Faces 项目。我以 this 为指导,虽然我理解堆栈跟踪的问题,但我不明白为什么(新的)Jakarta Faces 实施要求我提供旧的依赖项。

这是我在 pom.xml 文件中的内容(简体):

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ...>
  <packaging>war</packaging>

  <properties>
    <jakarta.platform.version>9.1.0</jakarta.platform.version>
    <java.version>11</java.version>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencyManagement>
    <dependencies>
       <dependency>
        <groupId>jakarta.platform</groupId>
        <artifactId>jakarta.jakartaee-web-api</artifactId>
        <version>${jakarta.platform.version}</version>
      </dependency>

      <dependency>
        <groupId>org.primefaces</groupId>
        <artifactId>primefaces</artifactId>
        <version>11.0.0</version>
        <classifier>jakarta</classifier>
      </dependency>
  </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>jakarta.platform</groupId>
      <artifactId>jakarta.jakartaee-web-api</artifactId>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.primefaces</groupId>
      <artifactId>primefaces</artifactId>
      <classifier>jakarta</classifier>
    </dependency>
  </dependencies>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.eclipse.jetty</groupId>
          <artifactId>jetty-maven-plugin</artifactId>
          <version>11.0.7</version>
          <dependencies>
            <dependency>
              <groupId>jakarta.platform</groupId>
              <artifactId>jakarta.jakartaee-web-api</artifactId>
              <version>${jakarta.platform.version}</version>
            </dependency>
          </dependencies>
        </plugin>
      </plugins>
    </pluginManagement>

    <plugins>
      <plugin>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>
</project>

web.xml 文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    version="3.1">
  <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>

  <welcome-file-list>
    <welcome-file>index.xhtml</welcome-file>
  </welcome-file-list>
</web-app>

TIP: I'm running the application with ./mvnw clean jetty:run.

这是整个堆栈跟踪:

java.lang.NoClassDefFoundError: com/sun/faces/util/Util
    at jakarta.faces.CurrentThreadToServletContext.getFactoryFinder (CurrentThreadToServletContext.java:52)
    at jakarta.faces.FactoryFinder.getFactory (FactoryFinder.java:260)
    at jakarta.faces.webapp.FacesServlet.acquireFacesContextFactory (FacesServlet.java:483)
    at jakarta.faces.webapp.FacesServlet.init (FacesServlet.java:328)
    at org.eclipse.jetty.servlet.ServletHolder$Wrapper.init (ServletHolder.java:1305)
    at org.eclipse.jetty.servlet.ServletHolder.initServlet (ServletHolder.java:633)
    at org.eclipse.jetty.servlet.ServletHolder.initialize (ServletHolder.java:415)
    at org.eclipse.jetty.servlet.ServletHandler.lambda$initialize (ServletHandler.java:690)
    at java.util.stream.SortedOps$SizedRefSortingSink.end (SortedOps.java:357)
    at java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:485)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto (AbstractPipeline.java:474)
    at java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining (StreamSpliterators.java:312)
    at java.util.stream.Streams$ConcatSpliterator.forEachRemaining (Streams.java:735)
    at java.util.stream.ReferencePipeline$Head.forEach (ReferencePipeline.java:658)
    at org.eclipse.jetty.servlet.ServletHandler.initialize (ServletHandler.java:714)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext (ServletContextHandler.java:392)
    at org.eclipse.jetty.webapp.WebAppContext.startContext (WebAppContext.java:1305)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart (ContextHandler.java:896)
    at org.eclipse.jetty.servlet.ServletContextHandler.doStart (ServletContextHandler.java:306)
    at org.eclipse.jetty.webapp.WebAppContext.doStart (WebAppContext.java:533)
    at org.eclipse.jetty.maven.plugin.MavenWebAppContext.doStart (MavenWebAppContext.java:294)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:93)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start (ContainerLifeCycle.java:171)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart (ContainerLifeCycle.java:121)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart (AbstractHandler.java:89)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:93)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start (ContainerLifeCycle.java:171)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart (ContainerLifeCycle.java:121)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart (AbstractHandler.java:89)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:93)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start (ContainerLifeCycle.java:171)
    at org.eclipse.jetty.server.Server.start (Server.java:469)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart (ContainerLifeCycle.java:114)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart (AbstractHandler.java:89)
    at org.eclipse.jetty.server.Server.doStart (Server.java:414)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:93)
    at org.eclipse.jetty.maven.plugin.JettyEmbedder.doStart (JettyEmbedder.java:223)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:93)
    at org.eclipse.jetty.maven.plugin.JettyRunMojo.startJettyEmbedded (JettyRunMojo.java:97)
    at org.eclipse.jetty.maven.plugin.AbstractWebAppMojo.startJetty (AbstractWebAppMojo.java:441)
    at org.eclipse.jetty.maven.plugin.AbstractWebAppMojo.execute (AbstractWebAppMojo.java:419)
    at org.eclipse.jetty.maven.plugin.JettyRunMojo.execute (JettyRunMojo.java:85)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.apache.maven.wrapper.BootstrapMainStarter.start (BootstrapMainStarter.java:39)
    at org.apache.maven.wrapper.WrapperExecutor.execute (WrapperExecutor.java:122)
    at org.apache.maven.wrapper.MavenWrapperMain.main (MavenWrapperMain.java:61)
Caused by: java.lang.ClassNotFoundException: com.sun.faces.util.Util
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass (SelfFirstStrategy.java:50)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass (ClassRealm.java:271)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass (ClassRealm.java:247)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass (ClassRealm.java:239)
    at jakarta.faces.CurrentThreadToServletContext.getFactoryFinder (CurrentThreadToServletContext.java:52)
    at jakarta.faces.FactoryFinder.getFactory (FactoryFinder.java:260)
    at jakarta.faces.webapp.FacesServlet.acquireFacesContextFactory (FacesServlet.java:483)
    at jakarta.faces.webapp.FacesServlet.init (FacesServlet.java:328)
    at org.eclipse.jetty.servlet.ServletHolder$Wrapper.init (ServletHolder.java:1305)
    at org.eclipse.jetty.servlet.ServletHolder.initServlet (ServletHolder.java:633)
    at org.eclipse.jetty.servlet.ServletHolder.initialize (ServletHolder.java:415)
    at org.eclipse.jetty.servlet.ServletHandler.lambda$initialize (ServletHandler.java:690)
    at java.util.stream.SortedOps$SizedRefSortingSink.end (SortedOps.java:357)
    at java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:485)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto (AbstractPipeline.java:474)
    at java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining (StreamSpliterators.java:312)
    at java.util.stream.Streams$ConcatSpliterator.forEachRemaining (Streams.java:735)
    at java.util.stream.ReferencePipeline$Head.forEach (ReferencePipeline.java:658)
    at org.eclipse.jetty.servlet.ServletHandler.initialize (ServletHandler.java:714)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext (ServletContextHandler.java:392)
    at org.eclipse.jetty.webapp.WebAppContext.startContext (WebAppContext.java:1305)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart (ContextHandler.java:896)
    at org.eclipse.jetty.servlet.ServletContextHandler.doStart (ServletContextHandler.java:306)
    at org.eclipse.jetty.webapp.WebAppContext.doStart (WebAppContext.java:533)
    at org.eclipse.jetty.maven.plugin.MavenWebAppContext.doStart (MavenWebAppContext.java:294)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:93)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start (ContainerLifeCycle.java:171)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart (ContainerLifeCycle.java:121)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart (AbstractHandler.java:89)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:93)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start (ContainerLifeCycle.java:171)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart (ContainerLifeCycle.java:121)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart (AbstractHandler.java:89)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:93)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start (ContainerLifeCycle.java:171)
    at org.eclipse.jetty.server.Server.start (Server.java:469)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart (ContainerLifeCycle.java:114)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart (AbstractHandler.java:89)
    at org.eclipse.jetty.server.Server.doStart (Server.java:414)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:93)
    at org.eclipse.jetty.maven.plugin.JettyEmbedder.doStart (JettyEmbedder.java:223)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:93)
    at org.eclipse.jetty.maven.plugin.JettyRunMojo.startJettyEmbedded (JettyRunMojo.java:97)
    at org.eclipse.jetty.maven.plugin.AbstractWebAppMojo.startJetty (AbstractWebAppMojo.java:441)
    at org.eclipse.jetty.maven.plugin.AbstractWebAppMojo.execute (AbstractWebAppMojo.java:419)
    at org.eclipse.jetty.maven.plugin.JettyRunMojo.execute (JettyRunMojo.java:85)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.apache.maven.wrapper.BootstrapMainStarter.start (BootstrapMainStarter.java:39)
    at org.apache.maven.wrapper.WrapperExecutor.execute (WrapperExecutor.java:122)
    at org.apache.maven.wrapper.MavenWrapperMain.main (MavenWrapperMain.java:61)
[INFO] Started ServerConnector@72b2c5ed{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
[INFO] Started Server@57f8951a{STARTING}[11.0.7,sto=0] @2371ms
[INFO] Scan interval sec = 10

您仍然需要包括一些 Jakara Faces 实现,在这种情况下,最简单的是 Mojarra,因为您使用的是标准 Jakarta Faces API,它已经需要一些 类 来自Mojarra 实现。

您可以在此处检查所有必需的依赖项:https://github.com/eclipse-ee4j/mojarra

如果您想使用 Myfaces,您需要将标准 Jakarta Faces API 替换为他们提供的 Jakata Faces API。