Buhake Sindi
Buhake Sindi

Reputation: 89199

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

I am writing a web application using JSF 2. I have downloaded mojarra-2.1.3-FCS-binary.zip and myfaces-core-assembly-2.1.3-bin.zip, and with each library, I'm getting the following exception:

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

For Mojarra, I included javax.faces.jar in WEB-INF/lib folder, and for MyFaces, I replace the jar with the following: myfaces-api-2.1.3.jar, myfaces-bundle-2.1.3.jar, myfaces-impl-2.1.3.jar.

I've included jstl-api-1.2.jar as well as jstl-impl-1.2.jar.

And ApplicationFactory is found in those jars. What is the issue with JSF in these instances?

I'm using Tomcat 7 to run my web application.

Upvotes: 5

Views: 21716

Answers (1)

BalusC
BalusC

Reputation: 1109422

This exception suggests that the Mojarra API was been loaded from the server-dedicated classloader while the Mojarra/MyFaces impl is loaded from the webapp-dedicated classloader. Remove the Mojarra JARs from Tomcat/lib, JRE/lib, JRE/lib/ext and/or Tomcat common lib and eventually all places in webapp's runtime classpath other than /WEB-INF/lib.

Upvotes: 3

Related Questions