3

I am embedding a Jetty 9.2 server in my JSF web app. It is supposed to be very easy to enable Weld in Jetty 9.1+ by enabling the Weld module, but I see no way to do that with the embedded server. Are there any examples of how to do this, and which classes are affected?

These are my listeners in web.xml:

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

This is how I'm starting my server:

    Server theServer = new Server();
    ServerConnector connector = new ServerConnector(theServer);
    connector.setHost(getHost());
    connector.setPort(getPort());
    connector.setIdleTimeout(getTimeout());
    theServer.addConnector(connector);
    WebAppContext webApp = new WebAppContext();
    webApp.setContextPath("/");
    File f = new File(getFileName());
    webApp.setWar(f.getAbsolutePath());
    webApp.setServer(theServer);
    theServer.setHandler(webApp);
    theServer.start();
    theServer.join()
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Ramesh
  • 613
  • 1
  • 10
  • 28
  • It looks like your example is based on an exploded war file, in which case it should work exactly the same. Perhaps there's a different problem in play? Do you get any stack traces? – John Ament Dec 29 '14 at 18:58
  • None of the required WebApp Configuration definitions seem to be present. Is this a complete server example? – Joakim Erdfelt Dec 29 '14 at 20:06
  • For someone still wrestling [try this answer](http://stackoverflow.com/questions/21624540/how-to-embed-weld-into-jetty-9-to-have-cdi-in-my-java-maven-project/33660160#33660160) – Bwire Nov 11 '15 at 21:30

1 Answers1

0

I got some help from Jesse McConnell at WebTide.

I needed to add the following file to my classpath: https://github.com/eclipse/jetty.project/blob/master/jetty-cdi/src/main/config/modules/cdi.mod

I also needed to add the jetty-cdi jar to my pom.

Ramesh
  • 613
  • 1
  • 10
  • 28
  • Would you mind sharing your code? I am trying to set up cdi with jetty and your approach seems promising, but I am still getting an NPE on my injected object in my servlet ... – Jan Galinski Jan 13 '15 at 00:01
  • I got quite far, but not all the way, and as I was under a tight deadline, I switched to embedding Tomcat, which is very easy with the Tomcat Maven plugin. Balus C has a nice blog post on enabling Weld with servlet containers, which, although a few versions old, is still mostly valid, and was all I needed to get embedded Tomcat running. – Ramesh Jan 17 '15 at 06:15