facebook

EJB Development Tools

If you need to support the simplified annotation-based POJO programming model introduced in Java EE 5, then EJB development tools are the right answer for you.  Here you will learn about:

  • These tools and EJB projects
  • Persistence support and EJB project preferences

This feature is available in MyEclipse.

1. MyEclipse EJB Development Tools

Enterprise Java Beans (EJB) have been the Java EE 5 standard for implementing Java enterprise business functionality and interfacing with database resources. MyEclipse EJB3 tools support the simplified annotation-based POJO programming model of Java EE 5. These tools enable you to develop and deploy an EJB3 bean in minutes. MyEclipse also supports traditional EJB2 development using integrated XDoclet annotation processing for rapid development of Java EE 1.4 enterprise java beans.

MyEclipse EJB Development tools include:

  • EJB Creation wizard
  • XML source and form-based editor for deployment descriptor customization
  • EJB Deployment Services

In addition, MyEclipse provides an EJB XDoclet attribute-oriented programming environment. See Using XDoclet in MyEclipse for more information.

  • Java editor enhancements to support code completion for XDoclet annotations and Java EE APIs
  • Auto-generation of EJB and Home interfaces and lookup utilities
  • ejb-jar.xml and application server specific deployment descriptor generation

2. EJB Projects

An EJB project is basically a Java project with the folder structure of an exploded EJB JAR file. The primary observable difference between an EJB project and a typical Java project is that an EJB project folder is decorated with the bean icon , and the project includes a runtime library and the opportunity to include an ejb-jar.xml deployment descriptor file. All EJB projects using JavaEE version less than 5.0 are created with a META-INF root folder and an empty META-INF/ejb-jar.xml deployment descriptor. For projects using Java EE5 or higher, this file is not required and you have the option to have this file generated for you. You can modify the ejb-jar.xml file as needed.


MyEclipse perspective view of an EJB project

Also depicted in the image above are the project’s metadata files. Note these files are typically hidden in the default Eclipse views due to the default use of the .* filename filter that hides dot prefixed files. The .project and .classpath files are standard Eclipse project information files. Do not delete or modify these files. Also, if your project is managed by a source code management tool such as CVS, be sure to include all these files as part of the project.

The image below displays the deployment information for the MyEclipse EJB project. If you did not generate the deployment descriptor during project creation, you can right-click the deployment descriptor placeholder, and select Generate Deployment Descriptor stub.


Deployment descriptor information

Project deployment can be customized using the project’s Deployment Assembly property. See MyEclipse Deployment Assembly for more information.

The Enterprise Archive (EAR) is the only required deployment model specified by the Java EE specification. Yet, the specification makes provision for application server-specific deployment models. Application servers such as JBoss and Weblogic support direct deployment of EJB Jar archives. A restriction of direct EJB Jar deployment is there is no provision for deployment of optional packages required by an EJB JAR archive. See Section 8.2 of the Java EE 1.4 specification for optional package deployment details.

You can set up Java project dependencies for EJB projects. See Configuring a Dependent Java Project for more information.

3.  Persistence Support in an EJB 3.x Project

When you create an EJB 3.x project, as an option you can add JPA support.


Creating an EJB project

If you include persistence support, the the JPA Facet page allows you to specify the runtime JNDI data source and select a MyEclipse database driver and schema. Your project must include the JPA facet to reverse engineer entities from a database. If you don’t add persistence support when you create the project, you can add the JPA facet by right-clicking the project and selecting MyEclipse>Project Facets>Install JPA Facet.


JPA configuration

Instead of relying only on libraries shipped with MyEclipse, you can download libraries to include in your project. Click  to add a user library.


Downloading a user library

You can change the EJB 3 project’s design time driver association at any time using the Java Persistence properties page. To open this page, right-click the project, and select Properties. Expand MyEclipse, and select Java Persistence.


Java Persistence properties for a specific project

3.1 Reverse Engineering Entities and DAOs from a Database

You can create Java classes containing contents of a database table by reverse engineering. A default package is generated by default in the projects source folder when you create the project. You can use this default package to contain the database artifacts.

To generate entities, right-click the project in the Package Explorer view, and select MyEclipse>Generate Entities & Facades. This launches the EJB3 Reverse Engineering wizard.

Note: Your project must include the JPA facet to perform this function.


Generating entities

You can also generate entities from the DB Browser view. Right-click the table you want to reverse engineer, and select EJB3 Reverse Engineering from the menu.


Entity generation from a DB table

The reverse engineering process is fully customizable. In the EJB3 Reverse Engineering wizard, you can choose the artifacts to generate and the database tables from which the artifacts are based. You also specify the Java package in which to place the artifacts.


Select artifacts to be reverse engineered

Following are several sample snippets of the code generated by the Reverse Engineering process.


Snippets of generated code

See MyEclipse JPA Development for more information on entity editing tools.

4. EJB Project Preferences

MyEclipse provides a number of customizable preferences. When you create a new EJB project, many wizard fields are pre-populated. The value of many of these fields is frequently derived from the MyEclipse system preferences.

To access the MyEclipse preferences, select Window>Preferences, expand MyEclipse>Java Enterprise Project, and select EJB Project.


MyEclipse EJB Project Template preferences

Note: Changing the EJB Project Template folders affects only new projects, not existing projects.