Chapter 2. Creating Enterprise Bean Projects
2.1. Create a Jakarta Enterprise Beans Archive Project Using Red Hat CodeReady Studio
This task describes how to create an Jakarta Enterprise Beans project in Red Hat CodeReady Studio.
Prerequisites
A server and server runtime for JBoss EAP have been configured in Red Hat CodeReady Studio.
NoteIf you set the Target runtime to 7.4 or a later runtime version in Red Hat CodeReady Studio, your project is compatible with the Jakarta EE 8 specification.
Create a Jakarta Enterprise Beans Project in Red Hat CodeReady Studio
Open the New EJB Project wizard.
- Navigate to the File menu, select New, then select Project.
When the New Project wizard appears, select EJB/EJB Project and click Next.
Figure 2.1. New EJB Project Wizard
Enter the following details:
- Project name: The name of the project that appears in Red Hat CodeReady Studio, and also the default file name for the deployed JAR file.
- Project location: The directory where the project files will be saved. The default is a directory in the current workspace.
- Target runtime: This is the server runtime used for the project. This will need to be set to the same JBoss EAP runtime used by the server that you will be deploying to.
- EJB module version: This is the version of the Jakarta Enterprise Beans specification that your enterprise beans will comply with. Red Hat recommends using 3.2.
Configuration: This allows you to adjust the supported features in your project. Use the default configuration for your selected runtime.
Click Next to continue.
The Java project configuration screen allows you to add directories containing Java source files and specify the directory for the output of the build.
Leave this configuration unchanged and click Next.
In the EJB Module settings screen, check Generate ejb-jar.xml deployment descriptor if a deployment descriptor is required. The deployment descriptor is optional in Jakarta Enterprise Beans 3.2 and can be added later if required.
Click Finish and the project is created and will be displayed in the Project Explorer.
Figure 2.2. Newly Created Jakarta Enterprise Beans Project in the Project Explorer
To add the project to the server for deployment, right-click on the target server in the Servers tab and choose Add and Remove.
In the Add and Remove dialog, select the resource to deploy from the Available column and click the Add button. The resource will be moved to the Configured column. Click Finish to close the dialog.
Figure 2.3. Add and Remove Dialog
You now have a Jakarta Enterprise Beans project in Red Hat CodeReady Studio that can build and deploy to the specified server.
If no enterprise beans are added to the project then Red Hat CodeReady Studio will display the warning stating An EJB module must contain one or more enterprise beans. This warning will disappear once one or more enterprise beans have been added to the project.
2.2. Create a Jakarta Enterprise Beans Archive Project in Maven
This task demonstrates how to create a project using Maven that contains one or more enterprise beans packaged in a JAR file.
Prerequisites
- Maven is already installed.
- You understand the basic usage of Maven.
Create a Jakarta Enterprise Beans Archive Project in Maven
Create the Maven project: A Jakarta Enterprise Beans project can be created using Maven’s archetype system and the
ejb-javaee7
archetype. To do this run themvn
command with parameters as shown:$ mvn archetype:generate -DarchetypeGroupId=org.codehaus.mojo.archetypes -DarchetypeArtifactId=ejb-javaee7
Maven will prompt you for the
groupId
,artifactId
,version
andpackage
for your project.$ mvn archetype:generate -DarchetypeGroupId=org.codehaus.mojo.archetypes -DarchetypeArtifactId=ejb-javaee7 [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Stub Project (No POM) 1 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] >>> maven-archetype-plugin:2.0:generate (default-cli) @ standalone-pom >>> [INFO] [INFO] <<< maven-archetype-plugin:2.0:generate (default-cli) @ standalone-pom <<< [INFO] [INFO] --- maven-archetype-plugin:2.0:generate (default-cli) @ standalone-pom --- [INFO] Generating project in Interactive mode [INFO] Archetype [org.codehaus.mojo.archetypes:ejb-javaee7:1.5] found in catalog remote Define value for property 'groupId': : com.shinysparkly Define value for property 'artifactId': : payment-arrangements Define value for property 'version': 1.0-SNAPSHOT: : Define value for property 'package': com.shinysparkly: : Confirm properties configuration: groupId: com.company artifactId: payment-arrangements version: 1.0-SNAPSHOT package: com.company.collections Y: : [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 32.440s [INFO] Finished at: Mon Oct 31 10:11:12 EST 2011 [INFO] Final Memory: 7M/81M [INFO] ------------------------------------------------------------------------ [localhost]$
-
Add your enterprise beans: Write your enterprise beans and add them to the project under the
src/main/java
directory in the appropriate sub-directory for the bean’s package. -
Build the project: To build the project, run the
mvn package
command in the same directory as thepom.xml
file. This will compile the Java classes and package the JAR file. The built JAR file is named-.jar
and is placed in thetarget/
directory.
You now have a Maven project that builds and packages a JAR file. This project can contain enterprise beans and the JAR file can be deployed to an application server.
2.3. Create an EAR Project Containing a Jakarta Enterprise Beans Project
This task describes how to create a new enterprise archive (EAR) project in Red Hat CodeReady Studio that contains a Jakarta Enterprise Beans project.
Prerequisites
A server and server runtime for JBoss EAP have been set up.
NoteIf you set the Target runtime to 7.4 or a later runtime version in Red Hat CodeReady Studio, your project is compatible with the Jakarta EE 8 specification.
Create an EAR Project Containing an Jakarta Enterprise Beans Project
Open the New Java EE EAR Project Wizard.
- Navigate to the File menu, select New, then select Project.
- When the New Project wizard appears, select Java EE/Enterprise Application Project and click Next.
Figure 2.4. New EAR Application Project Wizard
Enter the following details:
- Project name: The name of the project that appears in Red Hat CodeReady Studio, and also the default file name for the deployed EAR file.
- Project location: The directory where the project files will be saved. The default is a directory in the current workspace.
- Target runtime: This is the server runtime used for the project. This will need to be set to the same JBoss EAP runtime used by the server that you will be deploying to.
EAR version: This is the version of the Jakarta EE 8 specification that your project will comply with.
Red Hat recommends using Jakarta EE 8.
Configuration: This allows you to adjust the supported features in your project. Use the default configuration for your selected runtime.
Click Next to continue.
Add a new Jakarta Enterprise Beans module.
New modules can be added from the Enterprise Application page of the wizard. To add a new Jakarta Enterprise Beans Project as a module follow the steps below:
- Click New Module, uncheck Create Default Modules checkbox, select the Enterprise Java Bean and click Next. The New EJB Project wizard appears.
The New EJB Project wizard is the same as the wizard used to create new standalone Jakarta Enterprise Beans Projects and is described in Create Jakarta Enterprise Beans Archive Project Using Red Hat CodeReady Studio.
The minimum details required to create the project are:
- Project name
- Target runtime
- Jakarta Enterprise Beans module version
Configuration
All the other steps of the wizard are optional. Click Finish to complete creating the Jakarta Enterprise Beans Project.
The newly created Jakarta Enterprise Beans project is listed in the Java EE module dependencies and the checkbox is checked.
Optionally, add an
application.xml
deployment descriptor.Check the Generate application.xml deployment descriptor checkbox if one is required.
Click Finish.
Two new projects will appear: the Jakarta Enterprise Beans project and the EAR project.
Add the build artifact to the server for deployment.
Open the Add and Remove dialog by right-clicking in the Servers tab on the server you want to deploy the built artifact to in the server tab and then select Add and Remove.
Select the EAR resource to deploy from the Available column and click the Add button. The resource will be moved to the Configured column. Click Finish to close the dialog.
Figure 2.5. Add and Remove Dialog

You now have an Enterprise Application Project with a member Jakarta Enterprise Beans Project. This will build and deploy to the specified server as a single EAR deployment containing a Jakarta Enterprise Beans subdeployment.
2.4. Add a Deployment Descriptor to a Jakarta Enterprise Beans Project
A Jakarta Enterprise Beans deployment descriptor can be added to a Jakarta Enterprise Beans project that was created without one. To do this, follow the procedure below.
Prerequisites
- You have a Jakarta Enterprise Beans project in Red Hat CodeReady Studio to which you want to add a Jakarta Enterprise Beans deployment descriptor.
Add a Deployment Descriptor to a Jakarta Enterprise Beans Project
- Open the project in Red Hat CodeReady Studio.
Add a deployment descriptor.
Right-click on the Deployment Descriptor folder in the project view and select Generate Deployment Descriptor tab.
Figure 2.6. Adding a Deployment Descriptor
The new file,
ejb-jar.xml
, is created inejbModule/META-INF/
. Double-click on the Deployment Descriptor folder in the project view to open this file.
2.5. Runtime deployment information for beans
You can add runtime deployment information to your beans for performance monitoring.
For details about the available runtime data, see the ejb3
subsystem in the JBoss EAP management model. An application can include the runtime data as annotations in the bean code or in the deployment descriptor. An application can use both options.
Additional resources
-
For more information about available runtime data, see the
ejb3
subsystem in the JBoss EAP management model. - For more information about retrieving runtime data to evaluate performance, see the JBoss EAP Performance Tuning Guide.