Servlets with CDI
- get latest Jetty 9.1 archive and extract somewhere (I'll assume the Jetty root is called "jetty")
- in jetty/lib, create a folder called "weld" and download the weld-servlet and weld-servlet-core JARs into it. For injection in listeners to work, version should be 2.2.0.Beta1 or later.
- in jetty/modules, create a weld.mod as in this gist
- in jetty/start.ini, add a single line containing "--module=weld" to initialise Weld
In most cases, that should be it and you can deploy any compliant CDI application, even without a web.xml. In some cases though you may need to add the old-fashioned filter entry to the web.xml. See also: https://github.com/weld/core/pull/465
Servlets with CDI and JAX-RS 2.0 (using Jersey)
- get jersey-container-servlet, jersey-client (if you need it), and jersey-gf-cdi including all their dependencies and put them into a jetty/lib/jersey folder
- add a jetty/modules/jersey.mod file (similar to the Weld one) and activate the module with "--module=jersey"
This seems to work at least for a basic CDI+JAX-RS application: https://github.com/KlausBrunner/jaxrscditest
Note that WARs aren't properly classloader-separated if used in this way! Another option is to add the required JARs to the context XMLs of each WAR; see XMLs in this gist.