0

I created a Dyamic Web Project in Eclipse to try the login part of the example at http://www.simtay.com/simple-crud-web-application-with-jsf-2-1-primefaces-3-5-maven-and-jpa/ Project Facets I enabled in project properties are:

  • CDI
  • Dynamic web module
  • Java
  • JavaScript
  • JavaServerFaces
  • JPA

and as container I use TomEE.

The moment I try to start the login.xhtml page, I obtain

HTTP Status 404 - /LAI_pezzi_Login/faces/Login.xhtml

type Status report

message /LAI_pezzi_Login/faces/Login.xhtml

description The requested resource is not available.

Apache Tomcat (TomEE)/7.0.37

TomEE console:

SEVERE: StandardWrapper.Throwable
java.lang.IllegalStateException: No Factories configured for this Application. This happens if the faces-initialization does not work at all - make sure that you properly include all configuration settings necessary for a basic faces application and that all the necessary libs are included. Also check the logging output of your web application and your container for any exceptions!
If you did that and find nothing, the mistake might be due to the fact that you use some special web-containers which do not support registering context-listeners via TLD files and a context listener is not setup in your web.xml.
A typical config looks like this;
<listener>
  <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>

    at javax.faces.FactoryFinder._getFactory(FactoryFinder.java:286)
    at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:206)
    at javax.faces.webapp.FacesServlet.init(FacesServlet.java:116)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5033)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5317)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    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:722)

giu 14, 2013 5:17:59 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /PrimeFaces_DataTable_DB_editable threw load() exception
java.lang.IllegalStateException: No Factories configured for this Application. This happens if the faces-initialization does not work at all - make sure that you properly include all configuration settings necessary for a basic faces application and that all the necessary libs are included. Also check the logging output of your web application and your container for any exceptions!
If you did that and find nothing, the mistake might be due to the fact that you use some special web-containers which do not support registering context-listeners via TLD files and a context listener is not setup in your web.xml.
A typical config looks like this;
<listener>
  <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>

    at javax.faces.FactoryFinder._getFactory(FactoryFinder.java:286)
    at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:206)
    at javax.faces.webapp.FacesServlet.init(FacesServlet.java:116)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5033)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5317)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    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:722)

giu 14, 2013 5:17:59 PM org.apache.tomee.catalina.TomcatWebAppBuilder init
INFO: ------------------------- localhost -> /LAI_pezzi_Login
giu 14, 2013 5:17:59 PM org.apache.tomee.catalina.TomEEClassLoaderEnricher validateJarFile
WARNING: jar '/home/caterpillar/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/LAI_pezzi_Login/WEB-INF/lib/javax.persistence_1.0.0.jar' contains offending class: javax.persistence.Entity. It will be ignored.
giu 14, 2013 5:18:00 PM org.apache.openejb.config.ConfigurationFactory configureApplication
INFO: Configuring enterprise application: /home/caterpillar/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/LAI_pezzi_Login
giu 14, 2013 5:18:00 PM org.apache.openejb.config.ConfigurationFactory configureService
INFO: Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
giu 14, 2013 5:18:00 PM org.apache.openejb.config.AutoConfig createContainer
INFO: Auto-creating a container for bean LAI_pezzi_Login.Comp1241762921: Container(type=MANAGED, id=Default Managed Container)
giu 14, 2013 5:18:00 PM org.apache.openejb.assembler.classic.Assembler createRecipe
INFO: Creating Container(id=Default Managed Container)
giu 14, 2013 5:18:00 PM org.apache.openejb.core.managed.SimplePassivater init
INFO: Using directory /tmp for stateful session passivation
giu 14, 2013 5:18:00 PM org.apache.openejb.config.AutoConfig deploy
INFO: Configuring PersistenceUnit(name=LAI_pezzi_Login)
giu 14, 2013 5:18:00 PM org.apache.openejb.config.AutoConfig setJtaDataSource
INFO: Adjusting PersistenceUnit LAI_pezzi_Login <jta-data-source> to Resource ID 'My DataSource' from 'null'
giu 14, 2013 5:18:00 PM org.apache.openejb.config.AutoConfig setNonJtaDataSource
INFO: Adjusting PersistenceUnit LAI_pezzi_Login <non-jta-data-source> to Resource ID 'My Unmanaged DataSource' from 'null'
giu 14, 2013 5:18:00 PM org.apache.openejb.config.AppInfoBuilder build
INFO: Enterprise application "/home/caterpillar/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/LAI_pezzi_Login" loaded.
giu 14, 2013 5:18:00 PM org.apache.openejb.assembler.classic.Assembler createApplication
INFO: Assembling app: /home/caterpillar/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/LAI_pezzi_Login
giu 14, 2013 5:18:02 PM null
INFO: You have enabled runtime enhancement, but have not specified the set of persistent classes.  OpenJPA must look for metadata for every loaded class, which might increase class load times significantly.
giu 14, 2013 5:18:03 PM null
INFO: OpenJPA dynamically loaded a validation provider.
giu 14, 2013 5:18:03 PM org.apache.openejb.assembler.classic.ReloadableEntityManagerFactory createDelegate
INFO: PersistenceUnit(name=LAI_pezzi_Login, provider=org.apache.openjpa.persistence.PersistenceProviderImpl) - provider time 2951ms
giu 14, 2013 5:18:03 PM org.apache.openejb.cdi.CdiBuilder initSingleton
INFO: Existing thread singleton service in SystemInstance(): org.apache.openejb.cdi.ThreadSingletonServiceImpl@3f894493
giu 14, 2013 5:18:03 PM org.apache.openejb.cdi.OpenEJBLifecycle startApplication
INFO: OpenWebBeans Container is starting...
giu 14, 2013 5:18:03 PM org.apache.webbeans.plugins.PluginLoader startUp
INFO: Adding OpenWebBeansPlugin : [CdiPlugin]
giu 14, 2013 5:18:03 PM org.apache.webbeans.plugins.PluginLoader startUp
INFO: Adding OpenWebBeansPlugin : [OpenWebBeansJsfPlugin]
giu 14, 2013 5:18:03 PM org.apache.openejb.cdi.BeansDeployer validateInjectionPoints
INFO: All injection points are validated successfully.
giu 14, 2013 5:18:03 PM org.apache.openejb.cdi.OpenEJBLifecycle startApplication
INFO: OpenWebBeans Container has started, it took 23 ms.
giu 14, 2013 5:18:03 PM org.apache.openejb.assembler.classic.Assembler createApplication
INFO: Deployed Application(path=/home/caterpillar/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/LAI_pezzi_Login)
giu 14, 2013 5:18:04 PM org.apache.catalina.core.StandardContext addApplicationListener
INFO: The listener "org.apache.myfaces.webapp.StartupServletContextListener" is already configured for this context. The duplicate definition has been ignored.
giu 14, 2013 5:18:04 PM org.apache.myfaces.config.DefaultFacesConfigurationProvider getStandardFacesConfig
INFO: Reading standard config META-INF/standard-faces-config.xml
giu 14, 2013 5:18:04 PM org.apache.myfaces.config.DefaultFacesConfigurationProvider getWebAppFacesConfig
INFO: Reading config /WEB-INF/faces-config.xml
giu 14, 2013 5:18:04 PM org.apache.myfaces.config.DefaultFacesConfigurationProvider getClassloaderFacesConfig
INFO: Reading config : jar:file:/home/caterpillar/Universita/Programmazione/apache-tomee-plus-1.5.2/lib/openwebbeans-jsf-1.1.8.jar!/META-INF/faces-config.xml
giu 14, 2013 5:18:04 PM org.apache.myfaces.config.LogMetaInfUtils logArtifact
INFO: Artifact 'myfaces-api' was found in version '2.1.10' from path 'file:/home/caterpillar/Universita/Programmazione/apache-tomee-plus-1.5.2/lib/myfaces-api-2.1.10.jar'
giu 14, 2013 5:18:04 PM org.apache.myfaces.config.LogMetaInfUtils logArtifact
INFO: Artifact 'myfaces-impl' was found in version '2.1.10' from path 'file:/home/caterpillar/Universita/Programmazione/apache-tomee-plus-1.5.2/lib/myfaces-impl-2.1.10.jar'
giu 14, 2013 5:18:05 PM org.apache.myfaces.util.ExternalSpecifications isBeanValidationAvailable
INFO: MyFaces Bean Validation support enabled
giu 14, 2013 5:18:05 PM org.apache.myfaces.application.ApplicationImpl getProjectStage
INFO: Couldn't discover the current project stage, using Production
giu 14, 2013 5:18:05 PM org.apache.myfaces.config.FacesConfigurator handleSerialFactory
INFO: Serialization provider : class org.apache.myfaces.shared_impl.util.serial.DefaultSerialFactory
giu 14, 2013 5:18:05 PM org.apache.myfaces.config.annotation.DefaultLifecycleProviderFactory getLifecycleProvider
INFO: Using LifecycleProvider org.apache.myfaces.config.annotation.Tomcat7AnnotationLifecycleProvider
giu 14, 2013 5:18:05 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.apache.myfaces.webapp.StartupServletContextListener
java.lang.LinkageError: loader (instance of  sun/misc/Launcher$ExtClassLoader): attempted  duplicate class definition for name: "com/sun/crypto/provider/DESKeyGenerator"
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
    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:423)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at java.security.Provider$Service.getImplClass(Provider.java:1279)
    at java.security.Provider$Service.newInstance(Provider.java:1237)
    at javax.crypto.KeyGenerator.nextSpi(KeyGenerator.java:328)
    at javax.crypto.KeyGenerator.<init>(KeyGenerator.java:157)
    at javax.crypto.KeyGenerator.getInstance(KeyGenerator.java:207)
    at org.apache.myfaces.shared.util.StateUtils.findSecret(StateUtils.java:887)
    at org.apache.myfaces.shared.util.StateUtils.findSecret(StateUtils.java:876)
    at org.apache.myfaces.shared.util.StateUtils.initSecret(StateUtils.java:781)
    at org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces(AbstractFacesInitializer.java:148)
    at org.apache.myfaces.webapp.StartupServletContextListener.contextInitialized(StartupServletContextListener.java:119)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4797)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5291)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    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:722)

giu 14, 2013 5:18:05 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
giu 14, 2013 5:18:05 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/LAI_pezzi_Login] startup failed due to previous errors
giu 14, 2013 5:18:05 PM org.apache.openejb.assembler.classic.Assembler destroyApplication
INFO: Undeploying app: /home/caterpillar/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/LAI_pezzi_Login
giu 14, 2013 5:18:06 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-9080"]
giu 14, 2013 5:18:06 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-9009"]
giu 14, 2013 5:18:06 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 21399 ms

I know that the code must be adapted to my needs, but the web page as is, should at least start (and obiously have to fail when you trigger buttons) Here are most important files and the complete files list:

Login.xhtml

<ui:composition template="/templates/layout.xhtml"
     xmlns="http://www.w3.org/1999/xhtml"
     xmlns:f="http://java.sun.com/jsf/core"
     xmlns:h="http://java.sun.com/jsf/html"
     xmlns:ui="http://java.sun.com/jsf/facelets"
     xmlns:p="http://primefaces.org/ui"
>
     <ui:define name="content">
         <h:form styleClass="loginPanelStyle">
                 <p:growl id="msgs" showDetail="true" sticky="false" />                        
                <p:panelGrid columns="2">
                <f:facet name="header">
                    Login Panel
                </f:facet>
                <h:outputText value="Username : "></h:outputText>
                <p:inputText id="username" value="#{loginController.username}" required="true" requiredMessage="Please Enter Username!" message="fc">
                    <f:validateLength minimum="1" />  
                </p:inputText>
                <h:outputText value="Password : "></h:outputText>
                <p:password id="password" value="#{loginController.password}" required="true" requiredMessage="Please Enter password!">
                    <f:validateLength minimum="1" />  
                </p:password>
                <f:facet name="footer">
                <p:commandButton value="Submit" update="msgs" actionListener="#{loginController.login}" type="submit" icon="ui-icon-check" style="margin:0"></p:commandButton>
                </f:facet> 
            </p:panelGrid>
        </h:form>
     </ui:define>
</ui:composition>

LoginController.java

package controller;


import util.DateUtility;
import java.io.IOException;
import java.io.Serializable;
import java.security.Principal;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.enterprise.context.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Login Controller class allows only authenticated users to log in to the web application. 
 * @author Emre Simtay <emre@simtay.com>
 */

@Named
@SessionScoped
public class LoginController implements Serializable {
    @Inject
    private transient Logger logger;
    private String username;
    private String password;

    /** Creates a new instance of LoginController */
    public LoginController(){
    }

    //  Getters and Setters

    /** 
     * @return username
     */
    public String getUsername() {
            return username;
    }

    /**
     *
     * @param username
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /**
     *
     * @return  password
     */
    public String getPassword() {
    return password;
    }

    /**
     *
     * @param password
     */
    public void setPassword(String password) {
    this.password = password;
    }

    /**
     * Listen for button clicks on the #{loginController.login} action, 
     * validates the username and password entered by the user and
     * navigates to the appropriate page.
     * @param actionEvent 
     */
    public void login(ActionEvent actionEvent){

        FacesContext context = FacesContext.getCurrentInstance();  
        HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();                
        try {
                String navigateString = "";
                // Checks if username and password are valid if not throws a ServletException
                request.login(username, password);
                // gets the user principle and navigates to the appropriate page
                Principal principal = request.getUserPrincipal();
                if(request.isUserInRole("Administrator")){
                        navigateString = "/admin/AdminHome.xhtml";
                }else if(request.isUserInRole("Manager")){
                        navigateString = "/manager/ManagerHome.xhtml";
                }else if(request.isUserInRole("User")){
                        navigateString = "/user/UserHome.xhtml";
                }
                try {
                    logger.log(Level.INFO, "User ({0}) loging in #" +DateUtility.getCurrentDateTime(), request.getUserPrincipal().getName());
                    context.getExternalContext().redirect(request.getContextPath() + navigateString);
                } catch (IOException ex) {
                    logger.log(Level.SEVERE, "IOException, Login Controller" + "Username : " + principal.getName(), ex);
                    context.addMessage(null, new FacesMessage("Error!", "Exception occured")); 
                }
        } catch (ServletException e) {
                logger.log(Level.SEVERE, "IOException, Login Controller: The username or password you provided does not match our records.");
                context.addMessage(null, new FacesMessage("Error!", "The username or password you provided does not match our records."));                        
        }
    }

    /**
     * Listen for logout button clicks on the #{loginController.logout} action
     * and navigates to login screen.
     */
    public void logout(){

        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
        HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        logger.log(Level.INFO, "User ({0}) loging out #" +DateUtility.getCurrentDateTime(), request.getUserPrincipal().getName());
        if(session != null){
            session.invalidate();
        }
        FacesContext.getCurrentInstance().getApplication().getNavigationHandler().handleNavigation(FacesContext.getCurrentInstance(), null, "/Login.xhtml?faces-redirect=true");
    }

}

Files list:

ls -R
.:
build  src  WebContent

./build:
classes

./build/classes:
controller  META-INF  util

./build/classes/controller:
LoginController.class

./build/classes/META-INF:
persistence.xml

./build/classes/util:
DateUtility.class

./src:
controller  META-INF  util

./src/controller:
LoginController.java

./src/META-INF:
persistence.xml

./src/util:
DateUtility.java

./WebContent:
ErrorAccessDenied.xhtml  Login.xhtml  META-INF  resources  WEB-INF

./WebContent/META-INF:
MANIFEST.MF

./WebContent/resources:
css  primefaces-nz

./WebContent/resources/css:
default.css

./WebContent/resources/primefaces-nz:
images  theme.css

./WebContent/resources/primefaces-nz/images:
ui-bg_flat_30_cccccc_40x100.png           ui-bg_highlight-soft_35_222222_1x100.png  ui-icons_292cd1_256x240.png
ui-bg_flat_50_5c5c5c_40x100.png           ui-bg_highlight-soft_44_444444_1x100.png  ui-icons_a83300_256x240.png
ui-bg_glass_40_ffc73d_1x400.png           ui-bg_highlight-soft_80_1442c8_1x100.png  ui-icons_cccccc_256x240.png
ui-bg_highlight-hard_20_16475f_1x100.png  ui-bg_inset-hard_30_dedede_1x100.png      ui-icons_ffffff_256x240.png
ui-bg_highlight-soft_33_1258bf_1x100.png  ui-icons_222222_256x240.png

./WebContent/WEB-INF:
beans.xml  faces-config.xml  lib  web.xml

./WebContent/WEB-INF/lib:

P.S. Can be a problem having libraries in both TomEE and project files? I am forced to do that because when I used Tomcat I missed many libraries and I did not know where to get them, then I moved to TomEE

4

1 回答 1

2

The webapp's runtime classpath is a mess. The webapp's /WEB-INF/lib seems to contain JSF and JPA libraries which are already provided by TomEE itself as being a Java EE web profile compliant container.

Tomcat is a barebones JSP/Servlet container and does therefore not ship with e.g. JSF, JPA, EJB, etc. That's exactly why you need to provide and configure JSF, JPA, EJB, etc manually along with the webapp for Tomcat. But for TomEE (and Glassfish, JBoss AS, etc) that's thus absolutely not necessary and would only end up in classloading conflicts because of duplicate different versioned libaries in the runtime classpath.

Get rid of libraries in /WEB-INF/lib which are already provided by the target container itself.

于 2013-06-17T10:36:56.547 回答