Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 321068

Summary: JSF2 fails to initialize
Product: [RT] Jetty Reporter: Rostislav Hristov <rostislav.hristov>
Component: serverAssignee: Jan Bartel <janb>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3 CC: janb, jetty-inbox, moonblade.wolf
Version: unspecified   
Target Milestone: 8.0.0.M2   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Rostislav Hristov CLA 2010-07-27 17:23:19 EDT
Build Identifier: 8.0.0.M1

The issue was first described at http://dev.eclipse.org/mhonarc/lists/jetty-users/msg00506.html

An application using JSF2 is working properly with 8.0.0.M0 but fails in 8.0.0.M1. The exception is: 

java.lang.IllegalStateException: Application was not properly
initialized at startup, could not find Factory:
javax.faces.context.FacesContextFactory
       at javax.faces.FactoryFinder$FactoryManager.getFactory(FactoryFinder.java:800)
       at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:302)
       at javax.faces.webapp.FacesServlet.init(FacesServlet.java:162)
       at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:442)
       at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:270)
       at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
       at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:721)
       at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:279)
       at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:999)
       at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:610)
       at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:155)
       at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:384)
       at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:127)
       at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
       at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:165)
       at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:162)
       at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
       at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:165)
       at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
       at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:92)
       at org.eclipse.jetty.server.Server.doStart(Server.java:243)
       at org.mortbay.jetty.plugin.JettyServer.doStart(JettyServer.java:67)
       at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
       at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:437)
       at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:377)
       at org.mortbay.jetty.plugin.JettyRunMojo.execute(JettyRunMojo.java:546)
       at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
       at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
       at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
       at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
       at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
       at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
       at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
       at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
       at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
       at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
       at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:597)
       at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
       at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
       at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
       at org.codehaus.classworlds.Launcher.main(Launcher.java:375)

Reproducible: Always

Steps to Reproduce:
1. Create a blank Maven 2 project containing the following 2 files:

/pom.xml
-----------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<project
   xmlns="http://maven.apache.org/POM/4.0.0";
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
   xsi:schemaLocation="
       http://maven.apache.org/POM/4.0.0
       http://maven.apache.org/maven-v4_0_0.xsd";>

   <modelVersion>4.0.0</modelVersion>
   <groupId>com.foo</groupId>
   <artifactId>jetty-testcase</artifactId>
   <packaging>war</packaging>
   <version>0.1.0-SNAPSHOT</version>
   <name>jetty-testcase</name>

   <repositories>
       <repository>
           <id>net.java.download.maven2</id>
           <name>Java.net Repository</name>
           <url>http://download.java.net/maven/2</url>
       </repository>
   </repositories>

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

   <build>
       <plugins>
           <plugin>
               <groupId>org.mortbay.jetty</groupId>
               <artifactId>jetty-maven-plugin</artifactId>
               <version>8.0.0.M1</version>
           </plugin>
       </plugins>
   </build>

</project>


/src/main/webapp/WEB-INF/web.xml
-----------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app
   xmlns="http://java.sun.com/xml/ns/javaee";
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
   xsi:schemaLocation="
       http://java.sun.com/xml/ns/javaee
       http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd";
   version="3.0">

   <servlet>
       <servlet-name>faces</servlet-name>
       <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
       <load-on-startup>1</load-on-startup>
   </servlet>

</web-app>


2. Run "mvn clean jetty:run"
Comment 1 Jan Bartel CLA 2010-07-28 04:49:39 EDT
Fixed for 8.0.0.M2.

Wow, that was tricky to find! JSF has some pretty hairy startup configuration code. It turns out that in jetty-8.0.0.M0 the configuration code was being invoked by our TagLibConfiguration class which looked for .tld files and extracted any listeners (in this case the com.sun.faces.config.ConfigureListener from jsf-core.tld) and set them up in the container.

For jetty-8.0.0.M1 we removed the TagLibConfiguration class as the jsp-2.2 implementation we use has a ServletContainerIntializer that does the same job, but it appears its optimized for glassfish and explicitly ignores the jsf-core.tld file. That wouldn't have been a problem, as faces also has a ServletContainerInitializer that would do the configuration, except that it was being run AFTER the faces servlet was initialized due to the non-0 load-on-startup value in web.xml.

So I've moved the ServletContainerInitializers to always be called before any servlets are initialized.

As a workaround until 8.0.0.M2 comes out, you can define a listener in web.xml for the faces configuration listener:

<listener>
 <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
Comment 2 Albert CLA 2011-10-24 22:21:21 EDT
Hello, just created an account to join this conversation.
The problem is still happenning in jetty-maven-plugin:8.0.3.v20111011:run
I have to make use of the ConfigureListener to make this work.
Thanks !