java.lang.NoClassDefFoundError: javax/faces/context/FacesContextFactory

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25405894/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 07:58:32  来源:igfitidea点击:

java.lang.NoClassDefFoundError: javax/faces/context/FacesContextFactory

javamavenjsftomcat

提问by user3249829

All similar questions didn't help me, so I'm creating my own:

所有类似的问题都没有帮助我,所以我正在创建自己的:

I'm creating a JSF Webapp with Maven in Eclipse. To test it, I run it as a Maven build with the war:war goal, this works without errors. However, when I deploy the war-file to my local tomcat to test it, I get the following error message during startup:

我正在 Eclipse 中使用 Maven 创建一个 JSF Webapp。为了测试它,我将它作为带有 war:war 目标的 Maven 构建运行,这没有错误。但是,当我将 war 文件部署到本地 tomcat 进行测试时,我在启动过程中收到以下错误消息:

SCHWERWIEGEND: Critical error during deployment:
java.lang.NoClassDefFoundError: javax/faces/context/FacesContextFactory
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
        at java.net.URLClassLoader.access0(URLClassLoader.java:71)
        at java.net.URLClassLoader.run(URLClassLoader.java:361)
        at java.net.URLClassLoader.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:270)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1701)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:270)
        at javax.faces.FactoryFinder.getImplGivenPreviousImpl(FactoryFinder.java:618)
        at javax.faces.FactoryFinder.getImplementationInstance(FactoryFinder.java:509)
        at javax.faces.FactoryFinder.access0(FactoryFinder.java:139)
        at javax.faces.FactoryFinder$FactoryManager.getFactory(FactoryFinder.java:993)
        at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:343)
        at com.sun.faces.config.processor.FactoryConfigProcessor.verifyFactoriesExist(FactoryConfigProcessor.java:303)
        at com.sun.faces.config.processor.FactoryConfigProcessor.process(FactoryConfigProcessor.java:219)
        at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:360)

        at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:225)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)

        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:976)

        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1653)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: javax.faces.context.FacesContextFactory
        at java.net.URLClassLoader.run(URLClassLoader.java:366)
        at java.net.URLClassLoader.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
        ... 39 more

I have the following dependencies...

我有以下依赖项...

<dependencies>
  <dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-api</artifactId>
    <version>2.1.7</version>
  </dependency>
  <dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-impl</artifactId>
    <version>2.1.7</version>
  </dependency>
</dependencies>

and plugins:

和插件:

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.1</version>
        <configuration>
            <source>1.6</source>
            <target>1.6</target>
        </configuration>
    </plugin>
    <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.3</version>
    </plugin>
</plugins>

If you need further information, let me know. Thanks!

如果您需要更多信息,请告诉我。谢谢!

回答by BalusC

This problem suggests that you've another JSF API library somewhere else in the runtime classpath which is loaded by the JRE or Tomcat itself instead of by the webapp. This way the webapp-supplied JSF impl library can't find the right API, resulting in exactly this exception+trace.

此问题表明您在运行时类路径中的其他位置有另一个 JSF API 库,它由 JRE 或 Tomcat 本身而不是由 webapp 加载。这样 webapp 提供的 JSF impl 库找不到正确的 API,导致这个异常+跟踪。

In other words, the runtime classpath is dirty. Cleanup it. Get rid of JARs randomly placed in wrong places. This covers among others Tomcat's own /libfolder, the JRE's /liband /lib/extfolders. On the other hand, if you make sure that you never randomly put JARs in folders covered by the webapp's runtime classpath, then everything should be well.

换句话说,运行时类路径是脏的。清理它。摆脱随机放置在错误位置的 JAR。这包括 Tomcat 自己的/lib文件夹、JRE/lib/lib/ext文件夹等。另一方面,如果您确保从不将 JAR 随机放入 webapp 的运行时类路径覆盖的文件夹中,那么一切都应该没问题。

Another potential cause is that you're shipping multiple different versioned JSF API libraries in the webapp itself, but this information is not visible in the question in its current form. Exploring the /WEB-INF/libfolder of the Maven-built WAR file must give clues.

另一个潜在原因是您在 web 应用程序本身中提供了多个不同版本的 JSF API 库,但此信息在当前形式的问题中不可见。探索/WEB-INF/libMaven 构建的 WAR 文件的文件夹必须提供线索。