Question

I'd like to run a WebApp on Apache TomEE using Mojarra and Weld.

I put "javax.faces-2.1.21.jar" and "weld-servlet.jar" in my /WEB-INF/lib directory. I also added an empty "beans.xml" to my WEB-INF folder. My "web.xml" looks like this:


/WEB-INF/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>TestWeldOnTomEE</display-name>

  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</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>
  <context-param>
    <param-name>javax.faces.PROJECT_STATE</param-name>
    <param-value>Development</param-value>
  </context-param>

  <listener> 
    <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
  </listener>

</web-app>



Deploying the application on Tomcat works properly but with TomEE I get the following error on server startup:

SEVERE: Error configuring application listener of class org.jboss.weld.environment.servlet.Listener
java.lang.ClassNotFoundException: org.jboss.weld.environment.servlet.Listener
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1713)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558)
    at org.apache.tomee.catalina.LazyStopWebappClassLoader._loadClass(LazyStopWebappClassLoader.java:103)
    at org.apache.tomee.catalina.LazyStopWebappClassLoader.loadClass(LazyStopWebappClassLoader.java:98)
    at org.apache.tomee.catalina.JavaeeInstanceManager.newInstance(JavaeeInstanceManager.java:54)
    at org.apache.tomee.catalina.JavaeeInstanceManager.newInstance(JavaeeInstanceManager.java:48)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4733)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5291)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)



Is there a problem because TomEE already uses another CDI-Framework (OpenWebB)? Is there a possibility to get TomEE running with Weld?

Was it helpful?

Solution

You can definitely get TomEE to use Mojarra instead of MyFaces. Using Weld instead of OpenWebBeans, however is not possible due to the complexity of how CDI implementations are integrated.

For using Mojarra instead, just physically remove the <tomee-home>/lib/myfaces-*.jar files and put the Mojarra impl and api jar in there instead.

OTHER TIPS

The fundamental issue in the code you posted is that org.jboss.weld.environment.servlet.Listener is just needed for plain ServletContainers. E.g. integrating Weld into jetty or Tomcat if you DO NOT have a full Java EE server. (The pendant in Apache OpenWebBeans is WebBeansConfigurationListener)

But TomEE IS a full JavaEE6 server! Thus it comes with CDI enabled by default. You will not need to add anything yourself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top