Tutorial on Enterprise Java Bean
Enterprise Java Beans, or EJB, are the server-side components of Java technology, implementing an enterprise-level business logic, such as in transaction processing. They are platform- and application-independent with the capability to run over multiple distributed component technologies with remote object creation, invocation and deletion. EJB consists of two types of beans, namely session and entity beans. Session beans represent the various tasks a business has to perform, whereas entity beans represent business logic, such as a customer or inventory. These are generally persistent records stored in the form of a database. You can use Netbeans to create and manage EJBs.
Instructions
-
-
1
Click "Start" and choose "All Programs." Select "Netbeans IDE 6.7.1" to open the main screen.
-
2
Click "Server." To start the appropriate servers, right-click the server and choosing "Start" from the available options. Click "Files" and select "New Project" to open the New Project dialog box.
-
-
3
Highlight "Java EE," select "EJB Module" from the available options and click "Next" to open the New EJB Module dialog box. Enter a project name, project location and check the "Set as Main Project" box.
-
4
Click "Next" to open the Servers and Settings screen. Select the appropriate server from the "Server" drop-down menu and click "Finish" to create the project.
-
5
Click the Projects folder to show the new project you created. Right-click "<default package>" under the Source Packages folder and choose "New," "Java Package" to open the New Java Package dialog box. Enter a package name and click "Finish" to complete creating the new package.
-
6
Right-click the new package and choose "New Session Bean." Enter a EJB name, select the appropriate session type and check the "Remote" option under "Create Interface." Click "Finish" to generate the default code for the session bean.
-
7
Select the file that consists of the code for creating the bean, right-click anywhere in the code and select "Insert Code" to open the Generate screen.
-
8
Click "Add Business Method" to open the Add Business Method screen. Enter a name for the business in the "Name" text box and choose the appropriate return type. Enter the parameters and exceptions if there are any and click "OK" to generate the code. Make changes to the code as per your requirements.
-
9
Click the Services folder, right-click the appropriate server and choose "View Admin Console" to open the GlassFish Administration Console. Right-click the file in the Projects folder and select "Run" to execute the file. You see the message "Build Successful" after the code is compiled successfully.
-
10
Click the GlassFish Administration Console and choose "Applications." You see the newly created application in the list.
-
1
References
Resources
- Photo Credit kaffeebohnen image by Jens Weber from Fotolia.com