2

I'm trying to add Omnifaces 2.1 to a web application to use FullAjaxExceptionHandler and possibly other functionality in Omnifaces 2.1.

I've read and followed following post by BallusC and am still stuck: How to install and use CDI on Tomcat?

Tried to install Weld 2.2.9.Final and configure as described above. I am using the following:

JSF 2.2, EL 2.2, Servlet 3, Java 7

web.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="{name}" version="3.0">

Upon startup I am still getting the following exception:

Catalina.log:

INFO: Starting service Catalina
Aug 09, 2015 8:57:18 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.56
Aug 09, 2015 8:57:18 AM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor C:\xampp\tomcat\conf\Catalina\localhost\MITrace.xml
Aug 09, 2015 8:57:24 AM org.richfaces.webapp.ResourceServletContainerInitializer registerServlet
INFO: Auto-registered servlet ResourceServlet with mapping '/org.richfaces.resources/*'
Aug 09, 2015 8:57:24 AM org.omnifaces.ApplicationInitializer logOmniFacesVersion
INFO: Using OmniFaces version 2.1
Aug 09, 2015 8:57:26 AM com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Mojarra 2.2.6 ( 20140304-1537 https://svn.java.net/svn/mojarra~svn/tags/2.2.6@12949) for context '/MITrace'
Aug 09, 2015 8:57:27 AM com.sun.faces.spi.InjectionProviderFactory createInstance
INFO: JSF1048: PostConstruct/PreDestroy annotations present.  ManagedBeans methods marked with these annotations will have said annotations processed.
Aug 09, 2015 8:57:27 AM com.sun.faces.config.ConfigureListener contextInitialized
SEVERE: Critical error during deployment: 
java.lang.NoClassDefFoundError: Could not initialize class org.omnifaces.config.BeanManager
    at org.omnifaces.application.OmniApplication.<init>(OmniApplication.java:69)
    at org.omnifaces.application.OmniApplicationFactory.createOmniApplication(OmniApplicationFactory.java:89)
    at org.omnifaces.application.OmniApplicationFactory.getApplication(OmniApplicationFactory.java:54)
    at com.sun.faces.application.InjectionApplicationFactory.getApplication(InjectionApplicationFactory.java:93)
    at com.sun.faces.config.InitFacesContext.getApplication(InitFacesContext.java:144)
    at com.sun.faces.lifecycle.ClientWindowFactoryImpl.<init>(ClientWindowFactoryImpl.java:62)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at java.lang.Class.newInstance(Class.java:379)
    at javax.faces.FactoryFinder.getImplGivenPreviousImpl(FactoryFinder.java:721)
    at javax.faces.FactoryFinder.getImplementationInstance(FactoryFinder.java:553)
    at javax.faces.FactoryFinder.access$500(FactoryFinder.java:140)
    at javax.faces.FactoryFinder$FactoryManager.getFactory(FactoryFinder.java:1120)
    at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:379)
    at com.sun.faces.config.processor.FactoryConfigProcessor.verifyFactoriesExist(FactoryConfigProcessor.java:328)
    at com.sun.faces.config.processor.FactoryConfigProcessor.process(FactoryConfigProcessor.java:236)
    at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:435)
    at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:214)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4992)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5492)
    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:649)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:672)
    at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1861)
    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)

Localhost.log:

Aug 09, 2015 10:28:23 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Aug 09, 2015 10:28:25 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Aug 09, 2015 10:28:27 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.omnifaces.ApplicationListener
java.lang.ExceptionInInitializerError
    at org.omnifaces.ApplicationListener.checkCDIAvailable(ApplicationListener.java:63)
    at org.omnifaces.ApplicationListener.contextInitialized(ApplicationListener.java:55)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4994)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5492)
    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:649)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:672)
    at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1861)
    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.IllegalStateException: CDI BeanManager instance is not available in JNDI.
    at org.omnifaces.config.BeanManager.<init>(BeanManager.java:99)
    at org.omnifaces.config.BeanManager.<clinit>(BeanManager.java:49)
    ... 15 more
Caused by: java.lang.IllegalStateException: javax.naming.NamingException: Cannot create resource instance
    at org.omnifaces.util.JNDI.lookup(JNDI.java:92)
    at org.omnifaces.config.BeanManager.<init>(BeanManager.java:95)
    ... 16 more
Caused by: javax.naming.NamingException: Cannot create resource instance
    at org.apache.naming.factory.ResourceEnvFactory.getObjectInstance(ResourceEnvFactory.java:115)
    at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:842)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:830)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:830)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:167)
    at org.apache.naming.SelectorContext.lookup(SelectorContext.java:156)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at org.omnifaces.util.JNDI.lookup(JNDI.java:88)
    ... 17 more

The jar does indeed exist and has been added to the application.

What else could be causing this error?

Community
  • 1
  • 1
user1746582
  • 541
  • 1
  • 7
  • 19
  • What exactly is the root cause of that exception? (the bottommost one) How exactly does `` root declaration of your `web.xml` look like? – BalusC Aug 09 '15 at 06:13
  • Hi, thanks for your response. I've updated my post to include the bottommost exception from both catalina and localhost log files. I've also added the web-app root declaration as requested. – user1746582 Aug 09 '15 at 12:08
  • Ha, "Caused by: java.lang.IllegalStateException: CDI BeanManager instance is not available in JNDI". Try adding `BeanManagerjavax.enterprise.inject.spi.BeanManager` to your `web.xml` and let me know (it should however be done automatically, perhaps depending on Tomcat version) – BalusC Aug 09 '15 at 12:09
  • Hi, I tried adding the resource ref previously and it still threw errors. I kept the entry out as I noticed you said it wasn't required if using Weld 2.2.9. I've added it to bottom of web.xml and have updated the localhost.log with full exception raised. – user1746582 Aug 09 '15 at 12:31
  • Well, then it clearly isn't present in JNDI. That `` just manually registers it. It was just to exclude the one and other. Coming back to the problem, are you sure `/META-INF/context.xml` is all right and also present in the built WAR file? – BalusC Aug 09 '15 at 12:34
  • I've double checked and /META-INF/context.xml is there. as well as empty beans.xml in WEB-INF folder. Although I thought neither of those were necessary anyway? in any case they are there, including the Omnifaces jar file. – user1746582 Aug 09 '15 at 12:57
  • Bingo! I just tried to update the context.xml in the location suggested by this post: http://stackoverflow.com/questions/19852770/beanmanager-on-apache-tomcat-7-0-47-cannot-create-resource-instance, instead of updating /META-INF/context.xml and no error. I'm going to remove web.xml entries now and see if they are actually required. BBS. – user1746582 Aug 09 '15 at 12:59
  • You're the second with this problem. I haven't been able to reproduce let alone to understand this problem. Have you changed the Tomcat default installation or configuration in some way? How exactly are you deploying the webapp and managing/starting the server? – BalusC Aug 09 '15 at 20:07
  • Hi, locally I'm using the tomcat version that is bundled with Xampp. The only main thing I've done is add the application resource config under the conf/Catalina/localhost folder. Existing entries were required to load JDBC resources. I'll double check other config updated and report back. – user1746582 Aug 09 '15 at 20:18
  • Also I'm using the Xampp control panel for starting/stopping tomcat. I build war file in eclipse and manually copy to tomcat webapps folder. Then just start tomcat via Xampp control panel. View localhost, Catalina and app log for debugging. – user1746582 Aug 09 '15 at 20:33
  • The only main changes I have done on tomcat are adding these jars (ecj-3.7.1.jar, mysql-connector-java-5.1.15.jar) as well as setting up resource file as described above. You should be able to recreate issue easily using Xampp v3.2.1 – user1746582 Aug 10 '15 at 00:50

1 Answers1

0

Ok issue is now resolved. I can confirm the following for Apache Tomcat/7.0.56:

  • /META-INF/context.xml is not required however the resource entry is still required. To resolve the issue I added the resource entry in the following existing location: tomcat\conf\Catalina\localhost{resource-file-name}.xml

After that no errors appeared.

  • No related listeners need to be registered in web.xml
  • No related <resource-env-ref> are required in web.xml
  • /WEB-INF/beans.xml (empty) is required

Most of the above is covered here: http://balusc.blogspot.com.au/2013/10/how-to-install-cdi-in-tomcat.html

I wanted to provide an update to this though as some may find the resource loading part on tomcat helpful.

Thanks again BallusC. I've up-voted a similar post because the suggestion related to it helped me resolve this issue.

user1746582
  • 541
  • 1
  • 7
  • 19