Still on the Car rental Enterprise Application, I mentioned in the last post that I will be adding the Enterprise Java Bean Module to the project/tutorial. I will outline the steps to create an Enterprise Java Bean (EJB) Module which pertains to the tutorial/project and also for other purposes. Netbeans is the primary IDE for this tutorial/project.
An Enterprise JavaBeans (EJB) module is used to assemble one or more enterprise beans into a single deployable unit. An EJB module is stored in a standard Java archive (JAR) file.
An EJB module contains the following:
- One or more deployable enterprise beans.
- A deployment descriptor, stored in an Extensible Markup Language (XML) file. This file declares the contents of the module, defines the structure and external dependencies of the beans in the module, and describes how the beans are to be used at run time.It is not necessary to use XML deployment descriptors in EJB 3.0 modules, although XML descriptors are supported. Instead of deployment descriptors, you can use annotations to provide component metadata.
You can deploy an EJB module as a stand alone application, or combine it with other EJB modules or with Web modules to create a Java application. An EJB module is installed and run in an enterprise bean container.
If you want to package an EJB 3.0 module with a deployment descriptor, there are several ways to do it. You can package an EJB 3.0 module with an EJB 3.0 style session and/or message-driven beans exclusively; with an EJB 2.1 style session and/or message-driven beans exclusively, or a combination of 2.1 and 3.0 style beans. The XML deployment descriptor must be a Version 3.0 deployment descriptor. It is required that 2.1 entity beans are packaged in modules with 2.1 deployment descriptors.
EJB modules that contain EJB 3.0 beans must be at the EJB 3.0 specification level when running on the product. To set the EJB module to support EJB 3.0 beans, you can set the ejb-jar.xml deployment descriptor level to 3.0, or you can make sure that the module does not contain an ejb-jar.xml deployment descriptor. If the module level is EJB 2.1 or earlier, no EJB 3.0 functions, including annotation scanning or resource injection is performed at runtime.
Normally, the normal convention is to create an Enterprise Application project which will be packaged as a EAR file, add the EJB Module packaged as JAR file and finally the Web Module packaged as WAR file but I will be following the convention I love very much. It helps me keep everything simple and straight forward. My own convention is to:
- Create the EJB Module and package,
- Create the Web Module and package,
- Create the Enterprise Application, import the EJB and Web Modules and package into EAR to be deployed to the Application Server.
CREATING THE EJB MODULE WITH NETBEANS:
- From Netbeans New project Wizard, Select Java EE and Click on EJB Module from the list of options.
- Enter the project name (CarRental-ejb), other entries you can edit to your taste and System context. Click next.
- Choose Server which was configured earlier in the previous post, from the drop-down menu (Wildfly Application Server), leave Enterprise Application as None since the Enterprise Application have not been created and select Java EE version (Java EE7). Click on Finish.
The EJB Module for the tutorial/project will be created. In the next post, we will add the Entity, Interface and Bean Class.