java.lang.ClassNotFoundException:javax.faces.application.ApplicationFactory

时间:2011-11-01 07:53:17

标签: java jsf-2 tomcat7

我正在使用JSF 2编写Web应用程序。我已经下载了mojarra-2.1.3-FCS-binary.zip和myfaces-core-assembly-2.1.3-bin.zip,并且每个库,我都是得到以下异常:

java.lang.NoClassDefFoundError: javax/faces/application/ApplicationFactory
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:247)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1663)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:247)
    at javax.faces.FactoryFinder.getImplGivenPreviousImpl(FactoryFinder.java:591)
    at javax.faces.FactoryFinder.getImplementationInstance(FactoryFinder.java:482)
    at javax.faces.FactoryFinder.access$400(FactoryFinder.java:138)
    at javax.faces.FactoryFinder$FactoryManager.getFactory(FactoryFinder.java:959)
    at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:316)
    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:4723)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.ClassNotFoundException: javax.faces.application.ApplicationFactory
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 34 more

对于Mojarra,我在javax.faces.jar文件夹中包含了WEB-INF/lib,对于MyFaces,我用以下内容替换了jar:myfaces-api-2.1.3.jar,myfaces-bundle-2.1.3 .jar,myfaces-impl-2.1.3.jar。

我已经包含了jstl-api-1.2.jar以及jstl-impl-1.2.jar。

在这些罐子里发现了ApplicationFactory。在这些情况下,JSF有什么问题?

我正在使用Tomcat 7来运行我的Web应用程序。

1 个答案:

答案 0 :(得分:2)

此异常表明Mojarra API是从服务器专用的类加载器加载的,而Mojarra / MyFaces impl是从webapp专用的类加载器加载的。从Tomcat/libJRE/libJRE/lib/ext和/或Tomcat common lib中删除Mojarra JAR,最后删除除/WEB-INF/lib以外的webapp运行时类路径中的所有位置。