An enterprise bean is a managed Java component that can be combined
with other resources to create Java Enterprise Edition (Java EE) applications.
When you use the Application Server Toolkit to assemble Enterprise JavaBeans
(EJB) modules there are specific steps that you need to take for the assembly
tool to work with EJB 3.0 modules.
Before you begin
This topic assumes that you have created and unit tested an
enterprise bean (EJB file) that
you want to assemble in an
enterprise
application and deploy onto an application server.
About this task
Assemble an Enterprise JavaBeans (EJB) 3.0 module to contain enterprise
beans and related code artifacts. Group Web components, client code, and resource
adapter code in separate modules. After assembling an EJB module, you can
install it as a standalone application or combine it with other modules into
an enterprise application.
The Application Server Toolkit can be extended
with additional plug-ins to provide development support specifically for Java
Persistence API (JPA). See the Eclipse open source project, Dali, for a plug-in
that provides this extension. See the related links in this topic for the
Dali JPA tools Web site.
Note: Issues and problems using this plug-in need
to resolved through the Eclipse open source community.
Procedure
- Start an assembly tool.
- If you have not done so already, configure the assembly tool for
work on J2EE modules. Ensure that J2EE and EJB capabilities
are enabled.
- Create a Java project or J2EE utility project. EJB
3.0 modules should be created as a Java project or J2EE utility project. If
you create EJB 3.0 modules as an EJB project a J2EE 1.4 version of the ejb-jar.xml
file is added by default, which results in failure.
- Add the required EJB 3.0 JAR files from the WebSphere product to
the project's build path.
You need to add <WAS_HOME>/lib/j2ee.jar
to the project build path to resolve compilation dependencies on the new EJB
3.0 API classes. Code assist will work correctly once this is done. If you
define a server (see the J2EE Perspective), point the server to the WebSphere
Application Server install directory. Before creating the project, the project
will automatically refer to <WAS_HOME>/lib/j2ee.jar. Be sure to create
the server with the setting Run server with resources on Server.
- Include the new project in the EAR project as a utility JAR file.
For example, double-click on the EAR file's deployment descriptor to
start editing. Then, click on the Source tab to edit the descriptor's XML
file.
- Hand edit the EAR's application.xml source to add the EJB module
stanza with the following steps:
- Double-click on the EAR file's deployment descriptor file.
- Click the Source tab to edit the descriptor's XML source.
The new EJB 3.0 module (simple Java project name with .jar appended)
is now added and looks similar to the following:<module>
<ejb>MyEJB3Module.jar</ejb>
</module>
Once the module is added, the assembly tool might
flag the EAR file invalid if the EJB module that was added does not include
a deployment descriptor. You can fix this problem by editing the EAR file
project's properties. Select Validation properties and uncheck the EAR
Validator Build checkbox. After you rebuild the EAR file project, the
error will no longer display.
- Copy code artifacts (such as entity beans) from one EJB module
into a new EJB module.
- Optional: Add XML bindings files to the XML Catalog.
The Application Server Toolkit and Rational Application Developer can
be configured to recognize the XML binding files format to provide code assist
and validation by adding them to the XML Catalog. Using the XML bindings files
is only necessary if the default bindings are not desired or not sufficient.
To configure the XML Catalog in the assembly tools, follow these steps:
- Open the Preferences panel by clicking Windows > Preferences.
- Select XML Catalog under the Web and XML topic.
- Click Add.
- In the Location field, choose the file system ibm-ejb-jar-bnd_1_0.xml,
or import the schemas into a project and point to the XSD file. The example
below uses schemas imported into a project called schemas.
- In the Key Type: field, ensure that the value is Namespace Name.
- In the Key: field, ensure that the value is http:/websphere.ibm.com/xml/ns/javaee/ibm-ejb-jar_1_0.xsd.
- Click OK two times.
These steps enable code assist for editing the EJB JAR XML bindings
file.
What to do next
After you finish assembling your EJB module, you are ready to
deploy your module.
You
can generate EJB deployment code and deploy the module to a target server
in one step. In the Project Explorer view, right-click on your project and
click Deploy.