java.lang.IllegalAccessError: tried to access class com.sun.faces.context.ApplicationMap - jsf-2

i ve a jsf application which works fine on eclipse with tomcat 7. The problem happened when i packaged it (with mvn package..) and put the .war file in the tomcat webapps directory to deploy it.
in the tomcat console i got :
SEVERE: Error listenerStart
Nov 2, 2012 12:38:09 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/jsf_prime_ldap] startup failed due to previous errors
Nov 2, 2012 12:38:09 AM org.apache.catalina.loader.WebappClassLoader checkThread
LocalMapForLeaks
SEVERE: The web application [/jsf_prime_ldap] created a ThreadLocal with key of
type [com.sun.faces.config.ConfigureListener$1] (value [com.sun.faces.config.Con
figureListener$1#6972f1]) and a value of type [com.sun.faces.config.ConfigureLis
tener.ServletContextAdapter] (value [com.sun.faces.config.ConfigureListener$Serv
letContextAdapter#18fee4f]) but failed to remove it when the web application was
stopped. Threads are going to be renewed over time to try and avoid a probable
memory leak.
for more details about this problem, in the localhost's tomcat log file i have :
SEVERE: Exception sending context initialized event to listener instance of class com.sun.faces.config.ConfigureListener
java.lang.IllegalAccessError: tried to access class com.sun.faces.context.ApplicationMap from class com.sun.faces.config.InitFacesContext$ServletContextAdapter
at com.sun.faces.config.InitFacesContext$ServletContextAdapter.getApplicationMap(InitFacesContext.java:331)
at javax.faces.FactoryFinder$FactoryManagerCacheKey.<init>(FactoryFinder.java:850)
at javax.faces.FactoryFinder$FactoryManagerCache.getApplicationFactoryManager(FactoryFinder.java:719)
at javax.faces.FactoryFinder$FactoryManagerCache.access$100(FactoryFinder.java:691)
at javax.faces.FactoryFinder.setFactory(FactoryFinder.java:373)
at com.sun.faces.config.ConfigureListener.configure(ConfigureListener.java:666)
at com.sun.faces.config.ConfigureListener.configure(ConfigureListener.java:417)
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:348)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
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:618)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:963)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1600)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Nov 2, 2012 12:38:09 AM org.apache.catalina.core.StandardContext listenerStop
SEVERE: Exception sending context destroyed event to listener instance of class com.sun.faces.config.ConfigureListener
java.lang.IllegalAccessError: com/sun/faces/context/ApplicationMap
at com.sun.faces.config.InitFacesContext$ServletContextAdapter.getApplicationMap(InitFacesContext.java:331)
at javax.faces.FactoryFinder$FactoryManagerCacheKey.<init>(FactoryFinder.java:850)
at javax.faces.FactoryFinder$FactoryManagerCache.removeApplicationFactoryManager(FactoryFinder.java:810)
at javax.faces.FactoryFinder.releaseFactories(FactoryFinder.java:395)
at com.sun.faces.config.ConfigureListener.contextDestroyed(ConfigureListener.java:378)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4831)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5478)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
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:618)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:963)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1600)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
in the tomcat lib directory i have added these jars :
commons-beanutils-1.8.3/
commons-collections-3.2.1/
commons-digester-1.5/
commons-logging-1.1.1/
el-impl-2.2/
jsf-api-2.1.11/
jsf-impl-2.1.11/
jsp-api-2.1/jstl-1.2/
primefaces-3.4.1
The application's pom file :
<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.jsfprimeldap</groupId>
<artifactId>jsf_prime_ldap</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>jsf_prime_ldap Maven Webapp</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>prime-repo</id>
<name>Prime Repo</name>
<url>http://repository.primefaces.org</url>
</repository>
</repositories>
<dependencies>
<!-- PrimeFaces -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>3.4.1</version>
</dependency>
<!-- JSF 2 -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.11</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.11</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
</dependency>
<!-- EL -->
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>el-impl</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>1.1_02</version>
</dependency>
<!-- Tomcat 6 need this <dependency> <groupId>com.sun.el</groupId> <artifactId>el-ri</artifactId>
<version>1.0</version> </dependency> -->
</dependencies>
<build>
<finalName>jsf_prime_ldap</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
and my 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_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>jsf_prime_ldap</display-name>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
</web-app>
i didn't find any similar problem in google.. i wish to find the solution for this problem here.
thanks for help

in the tomcat lib directory i have added these jars : commons-beanutils-1.8.3/ commons-collections-3.2.1/ commons-digester-1.5/ commons-logging-1.1.1/ el-impl-2.2/ jsf-api-2.1.11/ jsf-impl-2.1.11/ jsp-api-2.1/jstl-1.2/ primefaces-3.4.1
Undo this step. Reinstall Tomcat altogether if you're uncertain. Do not ever touch it unless you really understand what you're doing. This is the cause of the whole problem. The classpath has become a messup and the duplicate JARs/classes are conflicting each other.
Webapp-specific JARs doesn't belong in there. They belong in /WEB-INF/lib, expect of the EL and JSP JARs; Tomcat has as being a JSP/Servlet/EL container already its own implementations for this. You should not put JSP/Servlet/EL libraries of a different container make/version in the classpath at all.
Technically, at least the both JSF JARs, the JSTL JAR and the PrimeFaces JAR should be in /WEB-INF/lib. However, as you're using Maven, it should already have taken care about this. You don't need to do anything regard this. So all you need to do is to free Tomcat from illegal JARs/classes.

Related

NullPointerException during initFaces of a MyFaces 2.0 application while migrating from WLS to Tomcat

I'm new to JSF and have been entrusted with the task of migrating what appears to me as an old MyFaces 2.0 webapp from WebLogic Server 12.1.3 to Tomcat (I chose Tomcat 9 and OpenWebBeans 2.0.20).
I followed the instructions at BalusC's page to integrate OpenWebBeans with Tomcat/webapp since just cdi-api-1.0.jar didn't do the trick.
I am seeing the following exception (please see the full stack trace further down).
20-Jun-2022 19:46:25.718 INFO [main] org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces ServletContext 'C:\apache-tomcat-9.0.63\webapps\app1\' initialized.
20-Jun-2022 19:46:25.767 INFO [main] org.primefaces.webapp.PostConstructApplicationEventListener.processEvent Running on PrimeFaces 4.0
20-Jun-2022 19:46:25.802 INFO [main] org.apache.myfaces.config.annotation.DefaultLifecycleProviderFactory.getLifecycleProvider Using LifecycleProvider org.apache.myfaces.config.annotation.AllAnnotationLifecycleProvider
20-Jun-2022 19:46:25.808 SEVERE [main] org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces An error occured while initializing MyFaces: null
java.lang.NullPointerException
at org.apache.myfaces.application.DefaultResourceHandlerSupport.calculateFacesServletMapping(DefaultResourceHandlerSupport.java:211)
Update #1:
After #tandraschko's suggestion to upgrade MyFaces from 2.0.0 to 2.0.25 & OpenWebBeans from 2.0.20 to 2.0.27, the above exception has evolved as follows:
28-Jun-2022 11:02:58.128 SEVERE [main] org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces An error occured while initializing MyFaces: null
java.lang.NullPointerException
at org.apache.webbeans.container.BeanManagerImpl.wrapExpressionFactory(BeanManagerImpl.java:1288)
Update #2:
After #tandraschko's suggestion to upgrade MyFaces from 2.0.0 to 2.3.10 and add StartupServletContextListener in web.xml, the latest exception is similar to the one above:
28-Jun-2022 12:20:17.674 SEVERE [main] org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces An error occured while initializing MyFaces: null
java.lang.NullPointerException
at org.apache.webbeans.container.BeanManagerImpl.wrapExpressionFactory(BeanManagerImpl.java:1288)
Update #3:
After #tandraschko's suggestion to match my pom.xml with that of the sample project, primefaces-test, there's no exception anymore!
However, launching the app on the browser resulted in the following exceptions being thrown (not related to the original question though):
30-Jun-2022 18:52:23.743 INFO [http-nio-8080-exec-6] org.apache.myfaces.extensions.cdi.jpa.impl.JpaModuleStartupObserver.logJpaModuleConfiguration [Started] MyFaces CODI JPA-Module v1.0.5
30-Jun-2022 18:52:23.781 INFO [http-nio-8080-exec-6] org.apache.myfaces.extensions.cdi.jsf2.impl.Jsf2ModuleStartupObserver.logJsfModuleConfiguration [Started] MyFaces CODI JSF-Module v1.0.5 for JSF 2.0
Used JSF implementation: MyFaces Core v2.3.10
config implementation: org.apache.myfaces.extensions.cdi.jsf.api.config.JsfModuleConfig$$OwbNormalScopeProxy0
config implementation: org.apache.myfaces.extensions.cdi.jsf.api.config.JsfModuleConfig
method: isInitialRedirectEnabled
value: true
method: isAlwaysKeepMessages
value: true
method: isUseViewConfigsAsNavigationCasesEnabled
value: true
method: isInvalidValueAwareMessageInterpolatorEnabled
value: true
config implementation: org.apache.myfaces.extensions.cdi.core.api.scope.conversation.config.WindowContextConfig$$OwbNormalScopeProxy0
config implementation: org.apache.myfaces.extensions.cdi.core.api.scope.conversation.config.WindowContextConfig
method: getWindowContextTimeoutInMinutes
value: 60
method: isUnknownWindowIdsAllowed
value: false
method: isCloseWindowContextEventEnabled
value: false
method: getMaxWindowContextCount
value: 64
method: isUrlParameterSupported
value: true
method: isAddWindowIdToActionUrlsEnabled
value: false
method: isCreateWindowContextEventEnabled
value: false
method: isEagerWindowContextDetectionEnabled
value: true
method: isCloseEmptyWindowContextsEnabled
value: false
config implementation: org.apache.myfaces.extensions.cdi.core.api.scope.conversation.config.ConversationConfig$$OwbNormalScopeProxy0
config implementation: org.apache.myfaces.extensions.cdi.core.api.scope.conversation.config.ConversationConfig
method: isStartConversationEventEnabled
value: false
method: isConversationRequiredEnabled
value: true
method: isCloseConversationEventEnabled
value: false
method: getConversationTimeoutInMinutes
value: 30
method: isAccessBeanEventEnabled
value: false
method: isUnscopeBeanEventEnabled
value: false
method: isScopeBeanEventEnabled
value: false
method: isRestartConversationEventEnabled
value: false
MessageContextConfig class: org.apache.myfaces.extensions.cdi.message.impl.DefaultMessageContextConfig
MessageInterpolator class: class org.apache.myfaces.extensions.cdi.jsf.impl.message.FacesMessageInterpolator
MessageResolver class: class org.apache.myfaces.extensions.cdi.jsf.impl.message.JsfAwareApplicationMessagesMessageResolver
MessageHandler class: class org.apache.myfaces.extensions.cdi.jsf.impl.message.JsfAwareMessageHandler
LocaleResolver class: class org.apache.myfaces.extensions.cdi.jsf.impl.message.JsfAwareLocaleResolver
FormatterFactory class: class org.apache.myfaces.extensions.cdi.message.impl.DefaultFormatterFactory
18:52:25.189 [http-nio-8080-exec-6] ERROR com.company.app1.enterprise.exception.app1ExceptionHandler - ExpHandler: current exception:class javax.faces.FacesException
18:52:25.190 [http-nio-8080-exec-6] ERROR com.company.app1.enterprise.exception.app1ExceptionHandler - ExpHandler: current exception component:null
18:52:25.192 [http-nio-8080-exec-6] ERROR com.company.app1.enterprise.exception.app1ExceptionHandler - ExpHandler: current exception phaseid:RENDER_RESPONSE(6)
18:52:25.200 [http-nio-8080-exec-6] ERROR com.company.app1.enterprise.exception.app1ExceptionHandler - ExpHandler: current exception: attributes{}
After scouring through post after post in SO, I wasn't able to find a similar issue nor any clue to crack my issue.
After decompiling myfaces-impl-2.0.0.jar, it seems that externalContext.getRequestServletPath() is returning null.
The webapp has extension mapping in web.xml (kindly see snippet further down) but I'm not sure if I'm looking at the right suspect.
Exception (Full Stack Trace after Update #2)
28-Jun-2022 12:20:17.674 SEVERE [main] org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces An error occured while initializing MyFaces: null
java.lang.NullPointerException
at org.apache.webbeans.container.BeanManagerImpl.wrapExpressionFactory(BeanManagerImpl.java:1288)
at org.apache.webbeans.jsf.OwbApplication.getExpressionFactory(OwbApplication.java:48)
at org.apache.myfaces.config.ManagedBeanBuilder.coerceToType(ManagedBeanBuilder.java:364)
at org.apache.myfaces.config.ManagedBeanBuilder.initializeProperties(ManagedBeanBuilder.java:347)
at org.apache.myfaces.config.ManagedBeanBuilder.buildManagedBean(ManagedBeanBuilder.java:163)
at org.apache.myfaces.webapp.AbstractFacesInitializer._createEagerBeans(AbstractFacesInitializer.java:339)
at org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces(AbstractFacesInitializer.java:218)
at org.apache.myfaces.webapp.StartupServletContextListener.contextInitialized(StartupServletContextListener.java:103)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4768)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5230)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:698)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:696)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1024)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1911)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:825)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:475)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1618)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:319)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:423)
at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:366)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:946)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:835)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:263)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:432)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:927)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.startup.Catalina.start(Catalina.java:772)
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.catalina.startup.Bootstrap.start(Bootstrap.java:345)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:476)
Configuration (as deduced & set up accordingly)
MyFaces 2.0
CODI 1.0.5
PrimeFaces 4.0
OpenWebBeans 2.0.20 (CDI 2.0 but beans_1_0 in beans.xml)
Tomcat 9
Java 8
Update 3: No jars were added to Tomcat's lib.
Update 3: The webapp's lib has the following 13 manually-added jars (with my notes against them):
Interestingly, everything works only if the 13 jars are placed in the webapp's lib (WEB-INF\lib) and not in Tomcat's lib!
Are there any recommendations or best practices on how to manage these 13 dependent jars?
commons-digester-1.8.jar
javax.ejb-api-3.2.2.jar
javax.persistence-api-2.2.jar
javax.ws.rs-api-2.0.1.jar
jersey-client-1.18.jar
jersey-core-1.18.jar (provided scope)
jersey-multipart-1.18.jar (provided scope)
jersey-server-1.18.jar (provided scope)
jersey-servlet-1.18.jar (provided scope)
myfaces-api-2.3.10.jar (one of the profile dependencies; should it be added to the POM as mentioned [here][2])
myfaces-impl-2.3.10.jar (one of the profile dependencies; should it be added to the POM as mentioned [here][2])
weblogic.jaxrs.internal.common_1.2.0.0.jar (need to be replaced with another JAX-RS provider?)
weblogic.jaxrs.server_3.0.0.0.jar (need to be replaced with another JAX-RS provider?)
pom.xml (abridged; modified now after years for Update #3)
<?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>TMapp1</groupId>
<artifactId>app1</artifactId>
<version>5.0</version>
<packaging>war</packaging>
<name>TM app1 Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<owb.version>2.0.27</owb.version>
</properties>
<dependencies>
<!-- app1 uses PrimeFaces 4.0 instead of 11.0.0 as primefaces-test 11.0.0 does. -->
<!-- <dependency> -->
<!-- <groupId>org.primefaces</groupId> -->
<!-- <artifactId>primefaces</artifactId> -->
<!-- <version>11.0.0</version> -->
<!-- </dependency> -->
<!-- javax.* APIs -->
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-atinject_1.0_spec</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jcdi_2.0_spec</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-interceptor_1.2_spec</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-annotation_1.3_spec</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-validation_2.0_spec</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.6</version>
</dependency>
<!-- app1 uses 3.1.0 instead of 4.0.1 as primefaces-test 11.0.0 does. -->
<!-- <dependency> -->
<!-- <groupId>javax.servlet</groupId> -->
<!-- <artifactId>javax.servlet-api</artifactId> -->
<!-- <version>4.0.1</version> -->
<!-- <scope>provided</scope> -->
<!-- </dependency> -->
<!-- app1 uses 2.2.4 instead of 3.0.0 as primefaces-test 11.0.0 does. -->
<!-- <dependency> -->
<!-- <groupId>javax.el</groupId> -->
<!-- <artifactId>javax.el-api</artifactId> -->
<!-- <version>3.0.0</version> -->
<!-- <scope>provided</scope> -->
<!-- </dependency> -->
<!-- OpenWebBeans -->
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-impl</artifactId>
<version>${owb.version}</version>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-jsf</artifactId>
<version>${owb.version}</version>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-web</artifactId>
<version>${owb.version}</version>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-el22</artifactId>
<version>${owb.version}</version>
</dependency>
<dependency>
<groupId>org.apache.bval</groupId>
<artifactId>bval-jsr</artifactId>
<version>2.0.6</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
</dependency>
<!-- start of apache-commons -->
<!-- Used by: app1 -->
<dependency>
<groupId<!-- ... -->
</dependency>
<!-- end of apache-commons -->
<dependency>
<!-- Used by: TODO: app1 -->
<groupId>org.apache.myfaces.extensions.cdi.bundles</groupId>
<artifactId>myfaces-extcdi-bundle-jsf20</artifactId>
<version>1.0.5</version>
</dependency>
<!-- primefaces? -->
<!-- Used by: app1 -->
<dependency> <!-- not used at compile time -->
<groupId>org.atmosphere</groupId>
<!-- ... -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>4.0</version>
</dependency>
<!-- Used by: app1 -->
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>2.2.4</version>
</dependency>
<!-- start of jersey libs -->
<dependency>
<!-- ... -->
</dependency>
<!-- end of jersey libs -->
<dependency>
<!-- Used by: app1 -->
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>primefaces</id>
<name>PrimeFaces Maven Repository</name>
<url>https://repository.primefaces.org</url>
<layout>default</layout>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<build>
<finalName>app1</finalName>
<plugins>
<!-- ... -->
</plugins>
<resources>
<!-- ... -->
</resources>
</build>
<profiles>
<profile>
<id>myfaces22</id>
<!-- ... -->
</profile>
<profile>
<id>myfaces23</id>
<!-- ... -->
</profile>
<profile>
<id>myfaces23next</id>
<!-- ... -->
</profile>
<profile>
<id>coverage</id>
<!-- ... -->
</profile>
</profiles>
</project>
web.xml
I removed what seems to be an old Mojarra remnant (following an error reported during startup):
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
from the web.xml below leaving me with only the 2 newly added listeners, WebBeansConfigurationListener (for OWB) and StartupServletContextListener (since Update #2: explicitly demanded it), in that order. Finally, cleaned it up to match the sample project, primefaces-test (Update #3).
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" >
<display-name>app1</display-name>
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>casablanca</param-value>
</context-param>
<!-- Enable PostConstruct on JSF ManagedBeans on Jetty (and Tomcat as well?) -->
<context-param>
<param-name>org.apache.myfaces.config.annotation.LifecycleProvider</param-name>
<param-value>org.apache.myfaces.config.annotation.NoInjectionAnnotationLifecycleProvider</param-value>
</context-param>
<listener>
<listener-class>org.apache.webbeans.servlet.WebBeansConfigurationListener</listener-class>
</listener>
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.company.app1.enterprise.service.health</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/health/*</url-pattern>
</servlet-mapping>
<session-config> <!-- set the default session time out to 60 minutes -->
<session-timeout>60</session-timeout>
<!-- set the Session Cookie as httpOnly -->
<!-- <cookie-config>
<http-only>true</http-only>
</cookie-config> -->
<!-- Added this for SPR HCSDM00273622 - Links to sign up new users not working properly -->
<tracking-mode>COOKIE</tracking-mode>
</session-config>
<filter>
<filter-name>ParameterEscapeFilter</filter-name>
<filter-class>com.company.app1.enterprise.filter.ParameterEscapeFilter</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>ParameterEscapeFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>primeFacesFileUploadFilter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>primeFacesFileUploadFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<filter>
<filter-name>GzipFilter</filter-name>
<filter-class>com.axeda.qpublic.filter.GZipServletFilter</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>GzipFilter</filter-name>
<url-pattern>*.js</url-pattern>
</filter-mapping>
<filter-mapping>
<!-- ... -->
</filter-mapping>
<resource-env-ref>
<resource-env-ref-name>BeanManager</resource-env-ref-name>
<resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
</resource-env-ref>
<mime-mapping>
<extension>xhtml</extension>
<mime-type>text/xhtml</mime-type>
</mime-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
beans.xml (untouched for years)
<?xml version="1.0" encoding="UTF-8"?>
<beans 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/beans_1_0.xsd">
<interceptors>
<class>org.apache.myfaces.extensions.cdi.jsf.impl.security.SecurityInterceptor</class>
<class>org.apache.myfaces.extensions.cdi.jsf.impl.listener.phase.ViewControllerInterceptor</class>
<class>org.apache.myfaces.extensions.cdi.jsf.impl.scope.conversation.CloseConversationGroupInterceptor</class>
<class>org.apache.myfaces.extensions.cdi.jsf.impl.config.view.PageParameterInterceptor</class>
<class>org.apache.myfaces.extensions.cdi.jsf.impl.config.view.PageParameterListInterceptor</class>
<class>org.apache.myfaces.extensions.cdi.jpa.impl.transaction.TransactionalInterceptor</class>
</interceptors>
</beans>
Why not use the latest MyFaces version? There is even a 2.0.24...
EDIT #1 - from the comments
I'd perform the following more steps based on the instructions from user #tandraschko in the comment thread below.
Side Note: I'm grateful to #tandraschko for the timely response & clear instructions.
Upgraded MyFaces version initially from 2.0.20 --> 2.0.24 but later to 2.3.10.
Upgraded OpenWebBeans version from 2.0.20 to 2.0.27.
Added the MyFaces listener StartupServletContextListener AFTER the OpenWebBeans one.
Cleaned up Maven dependencies to include all dependencies in the webapp's WEB-INF\lib (in contrast to a few at the sample which are of scope provided).

org.jboss.as.server.deployment.DeploymentUnitProcessingException: Failed to parse "/WEB-INF/web.xml" at [6,1]

I create simple app with PrimeFaces 3.4 and JSF 2.1. When I deploy the application in my JBoss AS 7.0, I encounter the following error
18:55:27,684 INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) Starting deployment of "Getting-started-with-Primefaces.war"
18:55:29,480 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC00001: Failed to start service jboss.deployment.unit."Getting-started-with-Primefaces.war".PARSE: org.jboss.msc.service.StartException in service jboss.deployment.unit."Getting-started-with-Primefaces.war".PARSE: Failed to process phase PARSE of deployment "Getting-started-with-Primefaces.war"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:121) [jboss-as-server-7.0.2.Final.jar:7.0.2.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824) [jboss-msc-1.0.1.GA.jar:1.0.1.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759) [jboss-msc-1.0.1.GA.jar:1.0.1.GA]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [:1.7.0_79]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [:1.7.0_79]
at java.lang.Thread.run(Thread.java:745) [:1.7.0_79]
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: Failed to parse "/C:/Users/marcos/Downloads/jboss-as-web-7.0.2.Final/jboss-as-web-7.0.2.Final/standalone/deployments/Getting-started-with-Primefaces.war/WEB-INF/web.xml" at [6,1]
at org.jboss.as.web.deployment.WebParsingDeploymentProcessor.deploy(WebParsingDeploymentProcessor.java:70)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:115) [jboss-as-server-7.0.2.Final.jar:7.0.2.Final]
... 5 more
My pom.xml
<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.itcuties.examples.webapps.simplejsf</groupId>
<artifactId>simple-jsf2-with-primefaces</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>simple-jsf2</name>
<url>http://maven.apache.org</url>
<dependencies>
<!-- Primefaces -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>3.4</version>
</dependency>
<!-- JSF 2 API -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.0-m07</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>primefaces-repository</id>
<name>Primefaces repository</name>
<url>http://repository.primefaces.org</url>
</repository>
</repositories>
<build>
<finalName>jsf2</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Update: on request, my web.xml:
<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">
<web-app>
<display-name>Simple JSF2 Application with Primefaces</display-name>
<!--
Current project stage. When it is set to 'Development' Primefaces give a lot of debug information on the screen.
-->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<!-- Staring JSF -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- JSF URL mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>
The problem in cause by, is in line [6,1] in the tag "web-app", but I do not understand.
Any idea what could be the problem?
In case you're getting exceptions, always head to the bottommost "Caused by" part for the root cause of all the trouble.
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: Failed to parse "/C:/Users/marcos/Downloads/jboss-as-web-7.0.2.Final/jboss-as-web-7.0.2.Final/standalone/deployments/Getting-started-with-Primefaces.war/WEB-INF/web.xml" at [6,1]
You see, a good exception and message is usually already the whole answer at its own. The server choked while parsing the webapp's web.xml file at line 6 and character 1.
Your web.xml look like this:
1 <web-app xmlns="http://java.sun.com/xml/ns/javaee"
2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
4 http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
5 version="3.0">
6 <web-app>
7 <display-name>Simple JSF2 Application with Primefaces</display-name>
.
. ...
.
. </web-app>
At line 6 there's a duplicate <web-app> declaration. Get rid of it.

Webapp runs correctly with jetty 9 maven plugin, but not with jetty runner

Being new to Maven, I'm trying to make an executable jar of my webapp with an embedded jetty. Unfortunately, I'm having many difficulties achieving this, and decided to follow a step-by-step progression: first using jetty-maven-plugin (OK, with a lot of pain), then using jetty-runner (KO, the matter of this SO question), and finally using embedded jetty (KO).
I've spent so much time doing this, having different exceptions depending on the jetty version and pulled so much hair out, that I finally decided to ask the community for some help.
I hope this question won't be marked as a duplicate of SO #12241989 (or any other similar), because I have the same kind of problem, but clearly not the same root cause since I'm using the same version of jetty-maven-plugin and jetty-runner.
Context
webapp uses JSF2 (mojarra 2.2.8) + CDI (weld) + Primefaces + Websockets
Configuration
1. Jetty plugin
excerpt from pom.xml
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
<jetty.groupId>org.eclipse.jetty</jetty.groupId>
<jetty.version>9.0.4.v20130625</jetty.version>
<jetty.descriptor>${project.basedir}/src/main/webapp/WEB-INF/web.xml</jetty.descriptor>
<jetty.env>${project.basedir}/src/main/webapp/WEB-INF/jetty-env.xml</jetty.env>
<jetty.contextPath>/</jetty.contextPath>
<jetty.overrideDescriptor>${project.basedir}/src/main/webapp/WEB-INF/jetty-web-override.xml</jetty.overrideDescriptor>
<myfaces.version>2.2.5</myfaces.version>
<mojarra.version>2.2.8</mojarra.version>
</properties>
...
<plugin>
<groupId>${jetty.groupId}</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
<webApp>
<contextPath>${jetty.contextPath}</contextPath>
<descriptor>${jetty.descriptor}</descriptor>
<jettyEnvXml>${jetty.env}</jettyEnvXml>
<overrideDescriptor>${jetty.overrideDescriptor}</overrideDescriptor>
</webApp>
<contextXml>
${project.basedir}/src/main/webapp/WEB-INF/jetty-context.xml
</contextXml>
</configuration>
</plugin>
jetty-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="serverClasses">
<Array type="java.lang.String">
<Item>
-org.eclipse.jetty.servlet.ServletContextHandler.Decorator
</Item>
</Array>
</Set>
</Configure>
jetty-env.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure id="webAppCtx" class="org.eclipse.jetty.webapp.WebAppContext">
<New id="appManager" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg>
<Ref id="webAppCtx" />
</Arg>
<Arg>BeanManager</Arg>
<Arg>
<New class="javax.naming.Reference">
<Arg>javax.enterprise.inject.spi.BeanManager</Arg>
<Arg>org.jboss.weld.resources.ManagerObjectFactory</Arg>
<Arg />
</New>
</Arg>
</New>
</Configure>
jetty-web-override.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">
<!-- CDI-->
<listener>
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>
<resource-env-ref>
<resource-env-ref-name>BeanManager</resource-env-ref-name>
<resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
</resource-env-ref>
<!-- mojarra -->
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
With this configuration, the application runs correctly. sigh of relief
2. Jetty runner
I believe the easiest way to reproduce the above configuration with jetty runner is using a jetty context xml file that describes my webapp. So I ended up with the following context file :
context.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/</Set>
<Set name="war">target/myapp.war</Set>
<Set name="descriptor">src/main/webapp/WEB-INF/web.xml</Set>
<Set name="overrideDescriptor">src/main/webapp/WEB-INF/jetty-web-override.xml</Set>
<Set name="serverClasses">
<Array type="java.lang.String">
<Item>
-org.eclipse.jetty.servlet.ServletContextHandler.Decorator
</Item>
</Array>
</Set>
<New id="appManager" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg>BeanManager</Arg>
<Arg>
<New class="javax.naming.Reference">
<Arg>javax.enterprise.inject.spi.BeanManager</Arg>
<Arg>org.jboss.weld.resources.ManagerObjectFactory</Arg>
<Arg />
</New>
</Arg>
</New>
</Configure>
Then when I run the jetty runner (with the same version):
java -jar jetty-runner-9.0.4.v20130625.jar context.xml
...everything seems OK, except the (annoying) fact that the startup listener of my app (annotated with Servlet 3.0 #WebListener) does not start.
And if I try to navigate to http://localhost:8080/, I get the following stack trace:
HTTP ERROR 500
Problem accessing /. Reason:
Server Error
Caused by:
javax.faces.view.facelets.TagAttributeException: /index.xhtml #119,66 src="/WEB-INF/include/#{applicationManager.layout}.xhtml" /index.xhtml #119,66 src="/WEB-INF/include/#{appli
cationManager.layout}.xhtml": java.lang.NullPointerException
at com.sun.faces.facelets.tag.TagAttributeImpl.getObject(TagAttributeImpl.java:358)
at com.sun.faces.facelets.tag.TagAttributeImpl.getValue(TagAttributeImpl.java:322)
at com.sun.faces.facelets.tag.ui.IncludeHandler.apply(IncludeHandler.java:112)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:203)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:203)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:203)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:203)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:87)
at com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:161)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:990)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:99)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698)
...
Caused by: javax.el.ELException: /index.xhtml #119,66 src="/WEB-INF/include/#{applicationManager.layout}.xhtml": java.lang.NullPointerException
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)
at com.sun.faces.facelets.tag.TagAttributeImpl.getObject(TagAttributeImpl.java:356)
... 60 more
Caused by: javax.el.ELException: java.lang.NullPointerException
at javax.el.BeanELResolver.getValue(BeanELResolver.java:368)
If I try to enforce the listening of my StartupListener class by specifying in web.xml:
<listener>
<listener-class>fr.mygroup.myapp.listeners.StartupListener</listener-class>
</listener>
...I get the same error.
Anyway, the fact that my StartupListener is not listened is clearly not the cause of the error but a consequence. But I can't figure out what's wrong with my jetty-runner configuration.
I desperately feel like it's a long way to go to an executable überjar of my webapp :(
Appendix
pom.xml
<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>fr.mygroupid</groupId>
<artifactId>myapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
<jetty.groupId>org.eclipse.jetty</jetty.groupId>
<jetty.version>9.0.4.v20130625</jetty.version>
<jetty.descriptor>${project.basedir}/src/main/webapp/WEB-INF/web.xml</jetty.descriptor>
<jetty.env>${project.basedir}/src/main/webapp/WEB-INF/jetty-env.xml</jetty.env>
<jetty.contextPath>/</jetty.contextPath>
<jetty.overrideDescriptor>${project.basedir}/src/main/webapp/WEB-INF/jetty-web-override.xml</jetty.overrideDescriptor>
<myfaces.version>2.2.5</myfaces.version>
<mojarra.version>2.2.8</mojarra.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>${jetty.groupId}</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
<webApp>
<contextPath>${jetty.contextPath}</contextPath>
<descriptor>${jetty.descriptor}</descriptor>
<jettyEnvXml>${jetty.env}</jettyEnvXml>
<overrideDescriptor>${jetty.overrideDescriptor}</overrideDescriptor>
</webApp>
<contextXml>
${project.basedir}/src/main/webapp/WEB-INF/jetty-context.xml
</contextXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
<finalName>${project.artifactId}</finalName>
</build>
<repositories>
<repository>
<id>ebi-repo</id>
<name>The EBI internal repository</name>
<url>http://www.ebi.ac.uk/~maven/m2repo</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>prime-repo</id>
<name>PrimeFaces Maven Repository</name>
<url>http://repository.primefaces.org</url>
<layout>default</layout>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>${mojarra.version}</version>
<scope>compile</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>${mojarra.version}</version>
<scope>compile</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet</artifactId>
<version>2.1.2.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<!-- Primefaces 5.1 -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.1</version>
</dependency>
<!-- Primefaces Themes -->
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>all-themes</artifactId>
<version>1.0.10</version>
</dependency>
<!-- Biomodels API -->
<dependency>
<groupId>uk.ac.ebi.biomodels</groupId>
<artifactId>biomodels-wslib</artifactId>
<version>1.21</version>
</dependency>
<!-- Ganymed SSH -->
<dependency>
<groupId>ch.ethz.ganymed</groupId>
<artifactId>ganymed-ssh2</artifactId>
<version>262</version>
</dependency>
<!-- Atmosphere -->
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>2.2.3</version>
</dependency>
<!-- Logback -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.2</version>
</dependency>
<!-- slf4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
</dependency>
<!-- GSON -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>
<!-- Apache commons -->
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
</dependencies>
</project>

Tomcat + CDI + Arquillian

I use Tomcat 7 together with CDI and for that I used the jee6-servlet-minimal-archetype from the Knappsack Maven Archetypes as a starting point.
Now I'd like to use Arquillian for testing the CDI beans, but even after searching for quite some time, I only found a number of problems related to the topic.
Can someone point me to a working setup (especially the right pom.xml to use) using Arquillian for CDI tests on Tomcat 7?
Edited 2012/09/11:
As pointed out in a comment below, I think to get my problem solved, I need someone to help me understanding the whole setup, rather than trying to solve a specific exception at some point.
So, how must the pom.xml and the test class look like, for having a CDI bean in a tomcat 7 and being able to test it with all the injection mechanisms in both an embedded and managed container? (By the way, why is there no remote container adapter for tomcat 7 anymore as it has been for 6?)
I already tried to adapt the tomcat 6 example, but couldn't make it work on tomcat 7.
Unfortunately, I haven't yet found or being told about a working example for my problem, but was able to come up with something that worked for me, which I want to show here - maybe it helps someone, since I assumed that the problem is not an exotic one and maybe someone can look over it and give me a hint in case something should be different.
/pom.xml (usable in eclipse [3.7] with a tomcat 7 [7.0.30], make sure that Project Properties/Deployment Assembly does not contain test classes/resources):
<?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.mycompany</groupId>
<artifactId>cditomcat</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>cditomcat</name>
<description>This pom is the base for a project using JSF2+CDI on a tomcat 7 and Arquillian for tests.</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- Java EE Dependencies -->
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.7</version>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.0.2-b10</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.0.0.GA</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet</artifactId>
<version>1.1.4.Final</version>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>1.0.0.CR5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.container</groupId>
<artifactId>shrinkwrap-container-tomcat-60</artifactId>
<version>1.0.0-beta-1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap</groupId>
<artifactId>shrinkwrap-api</artifactId>
<version>1.0.0-cr-1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap</groupId>
<artifactId>shrinkwrap-spi</artifactId>
<version>1.0.0-cr-1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
<artifactId>shrinkwrap-descriptors-api</artifactId>
<version>1.1.0-beta-1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
<artifactId>shrinkwrap-descriptors-impl</artifactId>
<version>1.1.0-beta-1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>cditomcat</finalName>
<testSourceDirectory>src/test/java</testSourceDirectory>
<plugins>
<!-- Facilitates downloading source and javadoc in Eclipse -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<wtpversion>2.0</wtpversion>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<!-- Ensures we are compiling at 1.6 level -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!-- Tomcat plugin for embedded tomcat -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<path>/${project.build.finalName}</path>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>tc7-embedded</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
<testResource>
<directory>src/test/resources/embedded</directory>
</testResource>
</testResources>
</build>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-tomcat-embedded-7</artifactId>
<version>1.0.0.CR3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>7.0.19</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>7.0.19</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>3.7</version>
<scope>test</scope>
</dependency>
<!-- Provided scoped dependencies for embedded container -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>7.0.29</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-coyote</artifactId>
<version>7.0.29</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>7.0.29</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-container-test-spi</artifactId>
<version>1.0.2.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-container-spi</artifactId>
<version>1.0.0.CR5</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
<id>tc7-managed</id>
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
<testResource>
<directory>src/test/resources/managed</directory>
</testResource>
</testResources>
</build>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-tomcat-managed-7</artifactId>
<version>1.0.0.CR3</version>
<scope>test</scope>
</dependency>
<!-- Provided scoped dependencies for embedded container -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>7.0.29</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-coyote</artifactId>
<version>7.0.29</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>7.0.29</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-container-test-spi</artifactId>
<version>1.0.2.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-container-spi</artifactId>
<version>1.0.0.CR5</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
/src/main/webapp/WEB-INF/web.xml (I still used version 2.5):
<?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_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>
<resource-env-ref>
<description>Object factory for the CDI Bean Manager</description>
<resource-env-ref-name>BeanManager</resource-env-ref-name>
<resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
</resource-env-ref>
</web-app>
/src/main/webapp/META-INF/context.xml (injection in Servlets, Listeners, Filters not used):
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<!-- disable storage of sessions across restarts -->
<Manager pathname=""/>
<Resource name="BeanManager" auth="Container" type="javax.enterprise.inject.spi.BeanManager" factory="org.jboss.weld.resources.ManagerObjectFactory"/>
</Context>
/src/main/resources/META-INF/beans.xml
/src/test/resources/in-container-beans.xml
(empty marker files are identically for application and test):
<?xml version="1.0" encoding="UTF-8"?>
<beans 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/beans_1_0.xsd">
</beans>
/src/test/resources/in-container-web.xml (same for embedded and managed):
<?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_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<env-entry>
<env-entry-name>name</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>Tomcat</env-entry-value>
</env-entry>
<listener>
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>
<resource-env-ref>
<resource-env-ref-name>BeanManager</resource-env-ref-name>
<resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
</resource-env-ref>
</web-app>
/src/test/resources/in-container-context.xml (same for embedded and managed):
<Context>
<Resource name="BeanManager" auth="Container"
type="javax.enterprise.inject.spi.BeanManager" factory="org.jboss.weld.resources.ManagerObjectFactory" />
</Context>
/src/test/resources/embedded/arquillian.xml (this file is for embedded only):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://jboss.org/schema/arquillian"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<engine>
<property name="deploymentExportPath">target</property>
</engine>
<container qualifier="tomcat" default="true">
<configuration>
<property name="tomcatHome">target/tomcat-embedded-7</property>
<property name="workDir">work</property>
<property name="appBase">webapps</property>
<property name="bindHttpPort">8889</property>
<property name="unpackArchive">true</property>
</configuration>
</container>
</arquillian>
/src/test/resources/managed/arquillian.xml (this file is for managed only):
<?xml version="1.0"?>
<arquillian
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://jboss.org/schema/arquillian"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<container qualifier="tomcat" default="true">
<configuration>
<property name="jmxPort">8099</property>
<property name="host">localhost</property>
<property name="port">8080</property>
<property name="user">tomcat</property>
<property name="pass">manager</property>
</configuration>
</container>
</arquillian>
For managed container deployment to work, tomcat's tomcat-users.xml file has to be extended to enable the manager, e.g.:
...
<role rolename="manager-gui" />
<role rolename="manager-jmx" />
<role rolename="manager-script" />
<user username="tomcat" password="manager"
roles="manager-gui,manager-jmx, manager-script" />
...
Finally, each arquillian test class has to have a deployment method as follows (I used Servlet 2.5):
...
#Deployment
#OverProtocol("Servlet 2.5")
public static WebArchive createDeployment() {
return ShrinkWrap
.create(WebArchive.class, "test.war")
.addClass(MyTest.class)
.addAsLibrary(
MavenArtifactResolver
.resolve("org.jboss.weld.servlet:weld-servlet:1.1.4.Final"))
.addAsWebInfResource("in-container-beans.xml", "beans.xml")
.addAsManifestResource("in-container-context.xml",
"context.xml").setWebXML("in-container-web.xml");
}
...
Weld has to be packaged, which is taken from local maven repository in my case as done in the question's referenced example (edited section) by the following code:
public class MavenArtifactResolver {
private static final String LOCAL_MAVEN_REPO =
System.getProperty("user.home") + File.separatorChar +
".m2" + File.separatorChar + "repository";
public static File resolve(String groupId, String artifactId, String version) {
return new File(LOCAL_MAVEN_REPO + File.separatorChar +
groupId.replace(".", File.separator) + File.separatorChar +
artifactId + File.separatorChar +
version + File.separatorChar +
artifactId + "-" + version + ".jar");
}
public static File resolve(String qualifiedArtifactId) {
String[] segments = qualifiedArtifactId.split(":");
return resolve(segments[0], segments[1], segments[2]);
}
}
Here's a setup that works for the Java EE certified version of Tomcat 7 (TomEE). It includes CDI and there are a handful of working Arquillian adapters:
http://tomee.apache.org/arquillian.html
Note that page mentions using properties to get the right port to use for sending requests to Tomcat. Ignore that. The correct approach is a field like this in your testcase:
#ArquillianResource
private URL url;
That will be the base URL of your webapp, ports and all.
You could take a look at the POM for the Tomcat-7 managed container of Arquillian, which adds the Weld-Servlet as a test dependency.
The Weld JARs are loaded into the Arquillian #Deployment defined in the test classes through the ShrinkWrap Maven Dependency Resolver. You'll also need to include an empty beans.xml file in the deployment. Note - although there is no CDI bean injected into the test class, Weld is used to inject the #Resource.

JSF2 on Jetty gives randomly 'zip file closed' but works when running from maven jetty plugin (jetty:run)

my JSF web app is giving randomly error: "zip file closed" when accessing files (like images, css, js). It is deployed on Jetty 7. It looks like some of those files are not loaded (some images are missing on a page).
java.lang.IllegalStateException: zip file closed
at java.util.zip.ZipFile.ensureOpen(ZipFile.java:403)
at java.util.zip.ZipFile.entries(ZipFile.java:298)
at java.util.jar.JarFile.entries(JarFile.java:217)
at org.eclipse.jetty.util.resource.JarFileResource.list(JarFileResource.java:261)
at org.eclipse.jetty.util.resource.ResourceCollection.list(ResourceCollection.java:421)
at org.eclipse.jetty.util.resource.Resource.getListHTML(Resource.java:509)
at org.eclipse.jetty.servlet.DefaultServlet.sendDirectory(DefaultServlet.java:741)
at org.eclipse.jetty.servlet.DefaultServlet.doGet(DefaultServlet.java:564)
When I run it from maven plugin (7.x) with jetty:run or jetty:run-war then I do not get any error.
What's more, accessing root path of web context gives that "zip file closed" error only when running on standalone jetty, but no such error when running from maven pluging, then is those directory view.
My web.xml:
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
pom.xml:
....
<dependencies>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>
....
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.5.1.v20110908</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
</configuration>
<dependencies>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.3</version>
</dependency>
</dependencies>
</plugin>
Any idea what could it be?
This issue has been fixed in jetty-7.6.0.RC2. The bug is caused by the JVM caching jar url connection streams.
According to the bug report, you will need to also add the following to the jetty.xml:
<Set class="org.eclipse.jetty.util.resource.Resource" name="defaultUseCaches">false</Set>
Jetty looks for your resources in the jar files in WEB-INF/lib. When it searches jsf-impl.jar it is somehow closed, probably by a JSF request. Perhaps jsf does its own resource handling and messes about with the files itself.
Anyway, the solution seems to be to move the jsf jars out of the war-file. Set your jsf dependency scope to provided so maven does not package them in the war file, and get them on the server, probably in the lib folder in jetty standalone.
I had the same issue and managed to solve it by going to etc\webdefault.xml and changing this param to false:
<init-param>
<param-name>gzip</param-name>
<param-value>true</param-value>
</init-param>

Resources