The first thing to do in developing enterprise beans is to create an EJB Module project that can contain one or more enterprise beans. Whereas a web application is a deployable Java EE component containing a collection of servlets, web pages, and JSP files, an EJB module is a deployable Java EE component that contains a collection of enterprise beans. To create an EJB Module project: Choose the EJB Module project template, under the Enterprise category (as shown in Figure 11-1). Figure 11-1. New Project wizard with EJB Module project type selected On the Name and Location page of the wizard, specify the location of the project, its name, and whether you want to add this EJB module to an existing enterprise application (EAR) project. You can add the module to an enterprise application project later, such as when you create the enterprise application project. Once you complete the wizard, your project is created and visible in the Projects window, as shown in Figure 11-2. For now, it contains no enterprise beans. The section Adding Enterprise Beans, Files, and Libraries to Your EJB Module later in this chapter explains how to populate the module. Figure 11-2. Projects window with EJB Module project showing You can open the Files window (shown in Figure 11-3) to see which directories and files have been created on disk. See the EJB Module Structure later in this chapter for a description of the conventions used for this structure. Figure 11-3. Files window with EJB Module project showing EJB Module Structure The Java BluePrints Solutions Catalog provides guidelines on how to structure your enterprise applications and EJB modules to ensure that they work properly with different application servers. When you create a project in the IDE, this Java BluePrints convention structure is respected. Following is a quick description of the structural elements of the built EJB module: The src/java folder, which contains all the Java source files in the application. The src/conf folder, which contains the enterprise deployment descriptors and the application server's specific deployment descriptors. The setup directory, which contains server-specific resource files. This folder does not appear until you have added any of these resources (through the Server Resources node in the Projects window or via the server's administration features). You can find additional information on these conventions at https://conventions.dev.java.net See Table 11-2 for information on how the various source elements of an EJB module map to their representation in the IDE and where they end up in the deployed component. |
Table 11-2. Matrix of EJB Module Elements and Their Representation in the IDEContent | Representationin the Projects Window | Representationin the Files Window | Location within theBuilt EJB JAR File (located in the dist folder) |
---|
Enterprise beans | Enterprise Beansnode | src/java folder | Root of the file | Java source files, helperclasses, enterprise bean Java files, etc. | Source Packagesnode | src/java folder | Package structure forthe JAR file | Unit tests | Test Packagesnode | test folder | N/A | Deployment descriptor(ejb-jar.xml, webservices.xml) | ConfigurationFiles node | src/conf folder | META-INF folder | Application server'sdeployment descriptors (sun-ejb-jar.xml, sun-cmp-mapping.xml, others for JBoss or WebLogic servers) | ConfigurationFiles node | src/conf folder | META-INF folder | Application serverspecificresources or scripts (such as SQL) | Server Resourcesnode (visible when some enterprise resources exist there) | setup folder | N/A. The resources inthis folder are registered automatically at deployment time for the Sun Application Server target. | Web services | Web Services node | src area (Javacode) | Package structure for the JAR file | Libraries | Libraries node | Location of the libraries folder | JAR libraries included in the EJB module JAR file, at the top location. | Test classpath entries | Test Librariesnode | test folder | N/A | Project metadata, including build script | Project Propertiesdialog box, which you can open by right-clicking the project's node and choosing Properties. | build.xml file,nbproject folder | N/A | EJB module build area(*.class files) | Not shown | build and build/generated | Main content for the EJBmodule archive JAR file. |
|