Creating applications that use Contexts and Dependency Injection (CDI)

You can use wizards to create applications that use Contexts and Dependency Injection (CDI).

Before you begin

Create a Java EE-faceted project (that is, a utility, EJB, web, connector, or application client project) in your workspace. For information about creating one of these projects see: Creating and configuring Java EE projects using wizards.

Procedure

  1. In the Java EE perspective, right-click your Java EE-faceted project, and select Properties > Project Facets.
  2. Right-click your project and select Properties > Project Facets, and select Context and dependency injection and click Apply and OK:
    CDI project facet
    To see the beans.xml file, expand:
    • Utility projects: <proj>/src/META-INF
    • EJB projects: <proj>/ejbModule/META-INF
    • WEB projects: <proj>/WebContent/WEB-INF
    • Connector projects: <proj>/connectorModule/META-INF
    • Application Client project: <proj>/appClientModule/META-INF
    At this point, it is virtually empty:
    <?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>
  3. You now have a CDI-enabled project.

Feedback