Developing Contexts and Dependency Injection (CDI) applications

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 more information, see Creating and configuring Java EE projects using wizards.

Procedure

  1. Right-click your Java EE-faceted project, and select Properties > Project Facets, and select Context and dependency injection, 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
    Now it is 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>
  2. You now have a CDI-enabled project.