Creating EJB projects in Eclipse

EJBs are packaged in a JAR file. Web applications are packaged in a Web Application aRchive (WAR). If EJBs are to be accessed remotely, then the client needs to have access to business interfaces. Therefore, EJB business interfaces and shared objects are packaged in a separate JAR, called EJB client JAR. Furthermore, if EJBs and web applications are to be deployed as one single application, then they need to be packaged in an EAR.

So, in most cases the application with EJBs is not a single project, but four different projects:

  • EJB project that creates EJB JAR
  • EJB client project that contains business classes and shared (between EJB and client) classes
  • Web project that generates WAR
  • EAR project that generates EAR containing EBJ JAR, EJB client JAR, and WAR

You can create each of these projects independently and integrate them. However, Eclipse gives you the option to create EJB projects, EJB client projects, and EAR projects with one wizard:

  1. Select File | New | EJB Project. Type CourseManagementEJBs in the Project name textbox:
Figure 7.4: New EJB Project wizard 

Make sure Target runtime is GlassFish 5 and EJB module version is 3.2 or later. From the Configuration drop-down list, select Default Configuration for GlassFish 5. In the EAR membership group, check the Add project to an EAR box.

  1. Select Next. On the next page, specify source and output folders for the classes. Leave the defaults unchanged on this page:
Figure 7.5: Select source and output folders
  1. The source Java files in this project would be created in the ejbModule folder. Click Next:
Figure 7.6: Creating an EJB client project
  1. Eclipse gives you the option to create an EJB client project. Select the option and click Finish.
  2. Since we are building a web application, we will create a web project. Select File | Dynamic Web Project. Set the project name as CourseManagementWeb:
Figure 7.7: New Dynamic Web Project
  1. Select the Add Project to an EAR checkbox. Since we have only one EAR project in the workspace, Eclipse selects this project from the drop-down list. Click Finish.

We now have the following four projects in the workspace:

Figure 7.8: Course Management projects

In the course management application, we will create a stateless EJB called CourseBean. We will use Java Persistence APIs (JPA) for data access and create a Course entity. See Chapter 4, Creating JEE Database Applications, for details on using JPAs. The CourseManagementEJBClient project will contain the EJB business interface and shared classes. In CourseManagementWeb, we will create a JSF page and a managed bean that will access the Course EJB in the CourseManagementEJBs project to get a list of courses.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.106.233