2

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:

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.access$100(URLClassLoader.java:71)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
        at java.net.URLClassLoader$1.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.access$400(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$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.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!

nitind
  • 19,089
  • 4
  • 34
  • 43
user3249829
  • 127
  • 1
  • 1
  • 6
  • have you checked this link http://stackoverflow.com/questions/7886035/could-not-find-factory-javax-faces-context-facescontextfactory – Adi Aug 20 '14 at 13:28
  • @Adi Yes, I added the listener as suggested, but it solve the problem for me. – user3249829 Aug 20 '14 at 13:32
  • it solved? if it doesn't, check if there are other jsf jars in tomcat libraries. try removing them so they won't conflit in classloading – Adi Aug 20 '14 at 13:36
  • @Adi: huh? Have you read the stack trace? The listener in question is already in there! – BalusC Aug 20 '14 at 13:51
  • @Adi _Didn't_ solve, sorry. I checked, there don't seem to be any jsf-jars in the lib folder of my tomcat. – user3249829 Aug 20 '14 at 13:52

1 Answers1

6

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.

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 /lib folder, the JRE's /lib and /lib/ext folders. 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.

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/lib folder of the Maven-built WAR file must give clues.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I found the problem! I had added PrimeFaces to the lib folder, I didn't think that would cause problems, but when you mentioned I should clean up my classpath, I got the idea to try and remove it. The tomcat is starting properly now. Thanks! – user3249829 Aug 20 '14 at 14:01
  • You're welcome. Though, PrimeFaces alone (in flavor of `primefaces.jar`) shouldn't cause this particular exception. It doesn't contain the JSF API at all. There's more at matter. For the difference, see http://stackoverflow.com/questions/2167509/jsf-implementations-and-component-libraries/ – BalusC Aug 20 '14 at 14:02