OmniFaces ClassNotFoundException CombinedResourceHandler

991 views Asked by At

I'm trying to get BootsFaces, OmniFaces and PrimeFaces running together with Tomcat 9:

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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>homepage</groupId>
<artifactId>xxx</artifactId>
<version>1.0-SNAPSHOT</version>

<name>homepage xxx</name>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <servlet.version>3.1.0</servlet.version>
    <jsf.version>2.2.13</jsf.version>
    <primefaces.version>6.0</primefaces.version>
    <bootfaces.version>1.0.1</bootfaces.version>
    <omnifaces.version>2.1</omnifaces.version>

</properties>

<dependencies>
    <!-- Servlet -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>${servlet.version}</version>
        <scope>provided</scope>
    </dependency>
    <!-- JSF -->
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>${jsf.version}</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>${jsf.version}</version>
        <scope>compile</scope>
    </dependency>
    <!-- PrimeFaces -->
    <dependency>
        <groupId>org.primefaces</groupId>
        <artifactId>primefaces</artifactId>
        <version>${primefaces.version}</version>
    </dependency>
    <dependency>
        <groupId>org.primefaces.extensions</groupId>
        <artifactId>primefaces-extensions</artifactId>
        <version>6.0.0</version>
        <scope>compile</scope>
    </dependency>
    <!-- Bootsfaces -->
    <dependency>
        <groupId>net.bootsfaces</groupId>
        <artifactId>bootsfaces</artifactId>
        <version>${bootfaces.version}</version>
        <scope>compile</scope>
    </dependency>
    <!-- Omnifaces -->
    <dependency>
        <groupId>org.omnifaces</groupId>
        <artifactId>omnifaces</artifactId>
        <version>${omnifaces.version}</version>
        <scope>compile</scope>
    </dependency>
</dependencies>

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
     version="3.1">

<welcome-file-list>
    <welcome-file>helloworld.xhtml</welcome-file>
</welcome-file-list>

<context-param>
    <param-name>primefaces.THEME</param-name>
    <param-value>bootstrap</param-value>
</context-param>
<context-param>
    <param-name>primefaces.FONT_AWESOME</param-name>
    <param-value>true</param-value>
</context-param>
<context-param>
    <param-name>BootsFaces_USETHEME</param-name>
    <param-value>default</param-value>
</context-param>

faces-config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
    version="2.2">

<application>
    <resource-handler>org.omnifaces.resourcehandler.CombinedResourceHandler</resource-handler>
</application>

And I get the following Stacktrace when trying to run my project on Tomcat 9:

  Cause: Unable to create a new instance of 'org.omnifaces.resourcehandler.CombinedResourceHandler': javax.faces.FacesException: org.omnifaces.resourcehandler.CombinedResourceHandler
at com.sun.faces.config.processor.AbstractConfigProcessor.createInstance(AbstractConfigProcessor.java:378)
at com.sun.faces.config.processor.ApplicationConfigProcessor.setResourceHandler(ApplicationConfigProcessor.java:856)
at com.sun.faces.config.processor.ApplicationConfigProcessor.process(ApplicationConfigProcessor.java:335)
at com.sun.faces.config.processor.AbstractConfigProcessor.invokeNext(AbstractConfigProcessor.java:152)
at com.sun.faces.config.processor.LifecycleConfigProcessor.process(LifecycleConfigProcessor.java:137)
at com.sun.faces.config.processor.AbstractConfigProcessor.invokeNext(AbstractConfigProcessor.java:152)
at com.sun.faces.config.processor.FactoryConfigProcessor.process(FactoryConfigProcessor.java:239)
at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:439)
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:227)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4715)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5179)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1702)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:482)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:431)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468)
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309)
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401)
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:324)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

Caused by: javax.faces.FacesException: org.omnifaces.resourcehandler.CombinedResourceHandler
at com.sun.faces.config.processor.AbstractConfigProcessor.loadClass(AbstractConfigProcessor.java:428)
at com.sun.faces.config.processor.AbstractConfigProcessor.createInstance(AbstractConfigProcessor.java:301)
... 53 more

Caused by: java.lang.ClassNotFoundException: org.omnifaces.resourcehandler.CombinedResourceHandler
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1275)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1109)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at com.sun.faces.util.Util.loadClass(Util.java:364)
at com.sun.faces.config.processor.AbstractConfigProcessor.loadClass(AbstractConfigProcessor.java:420)
... 54 more

I've also tried using older versions of OmniFaces, without success.

1

There are 1 answers

0
Stephan Rauh On BEST ANSWER

Your pom.xml is incomplete. If you used exactly the same pom.xml as listed above, you've ended up with a simple jar file instead of a war file, and Maven didn't add any of the libraries to the WEB-INF/lib folder.

To fix that, use these steps:

  • specify the <packaging>.
  • add the Maven war plugin
  • and - if you're using Eclipse - specify the Java version you want to use. Otherwise Eclipse assumes you're using Java 1.5, which won't work with BootsFaces.

By the way, you don't need the CombinedResourceHandler. It's just a great tool to speed up your application until http/2 arrives.

For the sake of convenience, here's the complete working 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/xsd/maven-4.0.0.xsd">                                                                                         
    <modelVersion>4.0.0</modelVersion>                                                                                                     

    <groupId>homepage</groupId>                                                                                                            
    <artifactId>xxx</artifactId>                                                                                                           
    <version>1.0-SNAPSHOT</version>                                                                                                        
    <packaging>war</packaging>                                                                                                             


    <name>homepage xxx</name>                                                                                                              

    <properties>                                                                                                                           
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>                                                                 

        <servlet.version>3.1.0</servlet.version>                                                                                           
        <jsf.version>2.2.13</jsf.version>                                                                                                  
        <primefaces.version>6.0</primefaces.version>                                                                                       
        <bootfaces.version>1.0.1</bootfaces.version>                                                                                       
        <omnifaces.version>1.12.1</omnifaces.version>                                                                                      
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>                                                                 
        <maven.compiler.source>1.7</maven.compiler.source>                                                                                 
        <maven.compiler.target>1.7</maven.compiler.target>                                                                                 
        <maven.compiler.testSource>1.7</maven.compiler.testSource>                                                                         
        <maven.compiler.testTarget>1.7</maven.compiler.testTarget>                                                                         
    </properties>                                                                                                                          

    <dependencies>                                                                                                                         
        <dependency>                                                                                                                       
            <groupId>javax.servlet</groupId>                                                                                               
            <artifactId>javax.servlet-api</artifactId>                                                                                     
            <version>${servlet.version}</version>                                                                                          
            <scope>provided</scope>                                                                                                        
        </dependency>                                                                                                                      
        <dependency>                                                                                                                       
            <groupId>com.sun.faces</groupId>                                                                                               
            <artifactId>jsf-api</artifactId>                                                                                               
            <version>${jsf.version}</version>                                                                                              
            <scope>compile</scope>                                                                                                         
        </dependency>                                                                                                                      
        <dependency>                                                                                                                       
            <groupId>com.sun.faces</groupId>                                                                                               
            <artifactId>jsf-impl</artifactId>                                                                                              
            <version>${jsf.version}</version>                                                                                              
            <scope>compile</scope>                                                                                                         
        </dependency>                                                                                                                      
        <dependency>                                                                                                                       
            <groupId>org.primefaces</groupId>                                                                                              
            <artifactId>primefaces</artifactId>                                                                                            
            <version>${primefaces.version}</version>                                                                                       
            <scope>compile</scope>                                                                                                         
        </dependency>                                                                                                                      
        <dependency>                                                                                                                       
            <groupId>org.primefaces.extensions</groupId>                                                                                   
            <artifactId>primefaces-extensions</artifactId>                                                                                 
            <version>6.0.0</version>                                                                                                       
            <scope>compile</scope>                                                                                                         
        </dependency>                                                                                                                      
        <dependency>                                                                                                                       
            <groupId>net.bootsfaces</groupId>                                                                                              
            <artifactId>bootsfaces</artifactId>                                                                                            
            <version>${bootfaces.version}</version>                                                                                        
            <scope>compile</scope>                                                                                                         
        </dependency>                                                                                                                      
        <dependency>                                                                                                                       
            <groupId>org.omnifaces</groupId>                                                                                               
            <artifactId>omnifaces</artifactId>                                                                                             
            <version>${omnifaces.version}</version>                                                                                        
            <scope>compile</scope>                                                                                                         
        </dependency>                                                                                                                      
    </dependencies>                                                                                                                        
    <build>                                                                                                                                
        <plugins>                                                                                                                          
            <plugin>                                                                                                                       
                <groupId>org.apache.maven.plugins</groupId>                                                                                
                <artifactId>maven-war-plugin</artifactId>                                                                                  
                <version>2.5</version>                                                                                                     
            </plugin>                                                                                                                      
        </plugins>                                                                                                                         
    </build>                                                                                                                               
</project>