Oracle® Containers for J2EE Orion CMP Developer's Guide 10g Release 3 (10.1.3.1) Part Number B28220-01 |
|
|
View PDF |
This chapter describes how you should approach the Orion CMP application development.
This chapter contains information on the following topics:
Typically, the EJB application development includes the following steps:
Setting up the application directory structure. See "Understanding the EJB Application Directory Structure" for more information.
Implementing the component interface. See "Implementing the Entity Bean Component Interface" for more information.
Implementing the bean class. See "Implementing the Entity Bean Class" for more information.
Implementing the home interface. See "Implementing the Entity Bean Home Interface" for more information.
Writing the EJB deployment descriptor. For more information, see the following:
Creating the front end.
Writing the front-end-specific deployment descriptor (for example, Web).
Writing the J2EE application definition (deployment descriptor) that combines the EJB module and the front end module into a J2EE application. This deployment descriptor defines all the modules of the application and the way they should be deployed. See "Packaging and Deploying EJB CMP Applications" for more information.
Compiling.
Creating the following archive files:
JAR file–contains the EJB part of the application.
WAR file–Web part of the application.
EAR file– contains a complete deployable J2EE application.
Note: You can use an Ant build file to compile all the.java files and create the .jar , .war and .ear files. |
For more information, see the following:
As a part of your application's deployment, you would have to install your application, bind the front end and start OC4J.
Even though you can develop your application in any way you like, you are advised to use consistent naming in order to easily locate your application. One approach would be to implement your EJB application under a single parent directory structure, segregating each module of the application into its own subdirectory.
The directory structure contains all the application files, including manually coded, as well as generated files.
Example 2-1 shows the addressbook directory. You should create the directory somewhere in your home directory (for example, in /home/jane.doe/projects/addressbook/
).
Example 2-1 Application Directory Structure
addressbook addressbook/etc addressbook/src addressbook/src/java addressbook/src/java/addressbook addressbook/src/java/addressbook/ejb addressbook/src/jsp addressbook/src/web
All .java
source files are placed under addressbook/src/java
. The client files (JSP, in this case) are placed under src/jsp
, and any .html
, .gif
, .jpg
and .css
files are put in addressbook/src/web
directory.
The directory addressbook/etc
contains all the necessary .xml
configuration files.
Note: To create the directory structure, you can use either shell ( .sh) (for UNIX and Linux systems) or batch ( .bat) (for Windows and OS/2 systems) files similar to the following:mkdir addressbook mkdir addressbook\etc mkdir addressbook\src mkdir addressbook\src\java mkdir addressbook\src\java\addressbook mkdir addressbook\src\java\addressbook\ejb mkdir addressbook\src\jsp mkdir addressbook\src\web Run your directory-making file in the directory where you plan to create the directory. |
The generated files are in the lib
and build
directories. Note that these directories are not included in the directory structure shown in Example 2-1 as they are typically created by the build script.
The archives, when created, are placed under addressbook/build/
.
Typically, the EJB development tools include the following:
The J2EE perspective: All of the EJB tools are accessible from the J2EE perspective. This perspective provides a layout in which the most commonly used actions, views, and wizards for J2EE and EJB development are easily accessible.
Tools for importing existing EJB JAR files.
Tools for creating enterprise beans and access beans: The EJB tools help you create enterprise beans (either with or without inheritance), including entity beans with container-managed persistence. The EJB deployment descriptor editor helps you set deployment descriptor and assembly properties for your enterprise beans.
You can also accomplish complementary enterprise bean development activities, such as writing and editing business logic, importing or exporting enterprise beans, and maintaining both your enterprise bean source code and generated code using the built-in Java development tools, along with the team and versioning capabilities.
You can also create access beans and add other attributes such as relationships. Access beans are Java bean wrappers for enterprise beans, which are typically used by client programs.
Tools for building data persistence into enterprise beans: The EJB mapping tools help you map entity enterprise beans to back-end data stores, such as relational databases. There is support for top-down, bottom-up, and meet-in-the-middle mapping development. You can also create schemas and maps from existing EJB JAR files.
Tools for generating deployment code: The EJB tools generate the deployment classes that allow your beans to run on an EJB server. You can launch wizards from the selected EJB projects or modules. These wizards provide lists of the enterprise beans that you can deploy (one or more at a time). These tools mask the complexities normally associated with creating deployment classes, such as generating RMI/IIOP stubs and EJB container-specific deployment code.
Support for entity beans with container-managed persistence is included in tools. The tools also let you create relational database tables for entity beans with container-managed persistence. After the deployment code is generated, you can export your enterprise beans to a JAR or EAR file for installation on an EJB server.
Tools for validating your enterprise beans for specification compliance: The EJB tools validate that your enterprise bean code is consistent and that it conforms to the rules defined by the EJB specification.
The EJB tools also automatically validate that access beans are constructed correctly and that they are consistent with their associated enterprise beans. Code validation usually occurs whenever you create or edit access beans.
JDeveloper 9.0.3's features cover all aspects of EJB 2.0 development from conception to implementation.
JDeveloper is a versatile tool with many capabilities. With regards to EJB development, JDeveloper enables you to do the following:
Develop EJB 2.0 entity beans with container-managed persistence using wizards.
Reverse-engineer database tables as EJB 2.0 entity beans with container-managed persistence.
Reverse engineer foreign key relationships in the database as EJB 2.0 entity beans with container-managed persistence.
Use the EJB Module Editor (see Figure 2-2) to edit all the EJB in the ejb-jar.xml
deployment descriptor.
Employ the EJB Verifier to validate ejb-jar.xml
deployment descriptor against DTD and to verify EJB classes for inconsistencies.
Develop EJB visually in a UML class diagram with synchronization between UML, code and deployment descriptor (see Figure 2-1).
Test EJB locally in the IDE using the built-in OC4J.
Generate standard EJB deployment archives.
Deploy easily to OC4J.
Pass command-line options in deployment profiles.
Add and assemble application deployment descriptors (see "Packaging and Deploying EJB CMP Applications" and "Deploying the CMP EJB Application to OC4J" for more information).
Use the Deployment Descriptor Editor for orion-web.xml
and application-client.xml
.
Import existing EAR files (see "Developing, Packaging and Deploying EJB Applications") as workspaces in JDeveloper using EAR Import Wizard for OC4J.
Figure 2-1 shows a UML representation with CMR reverse-engineered from the database using JDeveloper's extensive EJB modeling capabilities.
Figure 2-1 JDeveloper-generated UML Diagram with CMR
Figure 2-2 illustrates the EJB Module Editor that provides a common user interface for editing all the EJB in the ejb-jar.xml
deployment descriptor. The Relationships panel in the editor lets you add, edit and delete the container-managed relationships between entity beans in an intuitive way.
Figure 2-2 JDeveloper's EJB Module Editor
The following are the general steps for packaging and deploying an EJB application:
Create the deployment descriptor.
After implementing and compiling your classes, you must create the standard EJB deployment descriptor for all entity beans with container-managed persistence in the module. The XML deployment descriptor defined in the ejb-jar.xml
file (see "ejb-jar.xml File") describes the EJB module of the application. It describes the types of beans, their names and attributes. The structure for this file is mandated in the DTD file (you can access this file at http://java.sun.com/dtd/ejb-jar_2_0.dtd
).
Any OC4J services that you want to configure are also designated in the deployment descriptor. See Oracle Containers for J2EE Services Guide for information about the following container services:
Data sources
JTA
JNDI
JMS
RMI and RMI/IIOP
JCA
Java Object Cache
HTTPS
See Oracle Containers for J2EE Security Guide for information about the following container services:.
Security
CSv2
See Oracle Application Server Web Services Developer's Guide for information about Web services.
After creation, place the deployment descriptors for the EJB application in the META-INF
directory that is located in the same directory as the EJB classes, as Example 2-2 shows:
Archive the EJB application.
After you have finalized your implementation and created the deployment descriptors, archive your EJB application into a JAR file. The JAR file should include all EJB application files and the deployment descriptor.
For example, to archive your compiled EJB class files and XML files for the Addressbook example (see Example 2-1) into a JAR file, perform the following in the .../addressbook/ejb
directory:
% jar cvf addressbook-ejb.jar
This archives all files contained in the ejb
subdirectory within the JAR file:
META-INF/ META-INF/ejb-jar.xml addressbook/ addressbook/ejb/AddressEntry.class addressbook/ejb/AddressBook.class addressbook/ejb/AddressEntryBean.class
Prepare the EJB application for assembly.
To prepare the application for deployment, do the following:
Modify the application.xml
file with the modules of the enterprise Java application.
The application.xml
file acts as the manifest file for the application and contains a list of the modules that are included within your enterprise application. Use the <module>
element defined in the application.xml
file to designate what comprises your enterprise application, as Table 2-1 shows:
Table 2-1 Module Elements in the application.xml File
Element | Contents |
---|---|
EJB JAR file name. |
|
WAR file name in the |
|
Client JAR file name, if any. |
As Example 2-2 demonstrates, the application.xml
file is located under a META-INF
directory under the parent directory for the application. The JAR, WAR, and client JAR files should be contained within this directory, as follows:
META-INF/ META-INF/application.xml addressbook-ejb.jar addressbook-web.war
Because of the proximity, the application.xml
file refers to the JAR and WAR files only by name and relative path–not by full directory path. If these files were located in subdirectories under the parent directory, then these subdirectories must be specified in addition to the file name.
Archive all elements of the application into an EAR file.
Create the EAR file that contains the JAR, WAR, and XML files for the application. Note that the application.xml
file serves as the EAR manifest file.
To create the addressbook.ear
file, execute the following in the addressbook
directory shown in Example 2-1:
% jar cvf addressbook.ear
This step archives the application.xml
, the addressbook-ejb.jar
, the addressbook-web.war
, and the addressbook-client.jar
files into the addressbook.ear
file.
The following are the EJB deployment descriptor files that you use in CMP EJB applications deployed to OC4J:
The ejb-jar.xml
file is an EJB deployment descriptor file, and, when used, it describes the following:
mandatory structural information about all included enterprise beans
a descriptor for container-managed relationships, if any
an optional name of an ejb-client-jar.xml
file for the ejb-jar.xml
an optional application assembly descriptor
When it is required, the ejb-jar.xml
file describes EJB information applicable to any J2EE application server. This information may be augmented by application server-specific EJB deployment descriptor files (see "orion-ejb-jar.xml File").
The orion-ejb-jar.xml
file is an EJB deployment descriptor file that contains all OC4J-proprietary options. This file extends the configuration that you specify in the ejb-jar.xml
file (see "ejb-jar.xml File").
For more information about orion-ejb-jar.xml
deployment descriptor, see the following:
After archiving your application into an EAR file, deploy the application to OC4J. See Oracle Application Server Containers for J2EE User's Guide for information on how to deploy your application.