Java Reference
In-Depth Information
• META-INF/beans.xml in any JAR, EJB-JAR, application client JAR, or RAR in
the EAR or in any JAR archive or directory referred to by any of them by the
Class-Path of their META-INF/MANIFEST.MF
• WEB-INF/beans.xml of a WAR
• Any directory on the JVM class path with META-INF/beans.xml
If any of these locations has the beans.xml file, the EE server will scan all the classes in the
archive and manage any managed beans it finds.
13.5.2. Using the beans.xml deployment descriptor
Chapter 12 covered CDI and the beans.xml file in detail so we won't cover it again here.
But we'll quickly look at how to use the beans.xml file to package CDI in JAR archives,
EJB-JAR modules, and WAR.
JAR
Suppose you're working on a non-EE application, or you're working on a supporting utility
project to an EE application. In either case, you'll probably be creating a regular JAR
archive to distribute your code. For the classes in your archive to use CDI, add the META-
INF/beans.xml file. The following listing shows an example.
Listing 13.12. Structure of a JAR archive marked for CDI bean discovery
The beans.xml marks the archive for CDI bean discovery; is a class scanned by
CDI, and if it contains CDI annotations, it becomes a bean managed by CDI.
EJB-JAR
EJB-JAR modules are exactly the same as JAR archives. In the module, add the META-
INF/beans.xml file. The next listing shows an example.
 
Search WWH ::




Custom Search