There are two basic approaches to developing and deploying enterprise beans in
the EJB server (AE) environment:
- You can use one of the available integrated development environments
(IDEs) such as IBM VisualAge(TM) for Java Enterprise Edition. IDE tools
automatically generate significant parts of the enterprise bean code and
contain integrated tools for packaging and testing enterprise beans.
VisualAge for Java is the recommended development tool for the EJB server (AE)
environment. For more information on using VisualAge for Java, see Using VisualAge for Java.
- You can use the tools available in the Java Software Development Kit (SDK)
and the Advanced Application Server. For more information, see Developing and deploying enterprise beans with EJB server (AE) tools.
- Note:
- Deployment and use of enterprise beans for the EJB server (AE) environment
must take place on the Microsoft Windows NT(R) operating system, the IBM
AIX(R) operating systems, or the Sun Microsystems Solaris operating
system.
For information on developing enterprise beans in the EJB server (CB)
environment, see Tools for developing and deploying enterprise beans in the EJB server (CB) environment.
Before you can develop enterprise beans in VisualAge for Java, you must set up
the EJB development environment. You need to perform this setup task
only once. This setup procedure directs VisualAge for Java to import
all of the classes and interfaces required to develop enterprise beans.
After generating an enterprise bean, you complete its development by
following these general steps:
- Implement the enterprise bean class.
- Create the required abstract methods in the bean's home and remote
interfaces by promoting the corresponding methods in the bean class to the
appropriate interface.
- For entity beans, do the following:
- Create any additional finder methods in the home interface by using the
appropriate menu items.
- Create a finder helper interface, if required.
- Create the EJB module and corresponding deployment descriptor.
- Generate the deployment code for the bean.
VisualAge for Java contains a complete WebSphere Application Server run
time environment and a mechanism to generate a test client to test your
enterprise beans. For much more detailed information on developing
enterprise beans in VisualAge for Java, refer to the VisualAge for Java
documentation.
If you have decided to develop enterprise beans without an IDE, you
need at minimum the following tools:
- An ASCII text editor. (You can use also use a Java development tool
that does not support enterprise bean development.)
- The SDK Java compiler (javac) and Java Archiving tool
(jar).
- The WebSphere Application Assembly Tool and the WebSphere Administrative
Console.
This section describes steps you can follow to develop enterprise beans by
using these tools. The following tasks are involved in the development
of enterprise beans:
- Ensure that you have installed and configured the prerequisite software to
develop, deploy, and run enterprise beans in the EJB server (AE)
environment. For more information, see Installing and configuring the software for the EJB server (AE).
- Set the CLASSPATH environment variable required by different components of
the EJB server (AE) environment. For more information, see Setting the CLASSPATH environment variable in the EJB server (AE) environment.
- Write and compile the components of the enterprise bean. For more
information, see Creating the components of an enterprise bean.
- (Entity beans with CMP only) Create a finder helper interface
for each entity bean with CMP that contains specialized finder methods (other
than the findByPrimaryKey method). For more information, see Creating finder logic in the EJB server (AE).
- Create an EJB module and corresponding deployment descriptor by using the
Application Assembly Tool. For more information, see Creating an EJB module.
- (Entity beans only) Create a database schema to enable storage
of the entity bean's persistent data in a database. For more
information, see Creating a database for use by entity beans.
- Deploy the EJB module by using the Application Assembly Tool or the
WebSphere Administrative Console. For more information, see the
WebSphere InfoCenter and the online help available with the WebSphere
Administrative Console.
- Install the EJB module into an EJB server (AE) and start the server by
using the WebSphere Administrative Console.
You must ensure that you have installed and configured the following
prerequisite software products before you can begin developing enterprise
beans and EJB clients with the EJB server (AE):
- WebSphere Application Server Advanced Edition
- One or more of the following databases for use by entity beans with
container-managed persistence (CMP):
- DB2
- Oracle
- Sybase
- Informix
- Microsoft SQL Server
- InstantDB
- The Java Software Development Kit (SDK)
For information on the appropriate version numbers of these products and
instructions for setting up the environment, see the WebSphere
InfoCenter.
In addition to the classes.zip file contained in the SDK, the following
WebSphere JAR files must be appended to the CLASSPATH environment variable for
developing enterprise beans:
- ejs.jar
- ujc.jar
- otherDeployedBean.jar (if the enterprise bean uses
another enterprise bean). This is the deployed JAR file containing the
enterprise bean being used by this enterprise bean.
For developing and running an EJB client, the following WebSphere JAR files
must be appended to the CLASSPATH environment variable:
- ejs.jar
- ujc.jar
- servlet.jar (required by EJB clients that are servlets)
- otherDeployedBean.jar. This is the deployed JAR
file containing the enterprise bean being used by this EJB client.
If you use an ASCII text editor or a Java development tool that does not
support enterprise bean development, you must create each of the components
that compose the enterprise bean you are creating. You must ensure that
these components match the requirements described in Developing enterprise beans.
To manually develop a session bean, you must write the bean class, the
bean's home interface, and the bean's remote interface. To
manually develop an entity bean, you must write the bean class, the
bean's primary key class, the bean's home interface, the bean's
remote interface, and if necessary, the bean's finderHelper
interface.
After you have properly coded these components, use the Java compiler to
create the corresponding Java class files. For example, because the
components of the example Account bean are stored in a specific directory, the
bean components can be compiled by issuing the following command:
C:\MYBEANS\COM\IBM\EJS\DOC\ACCOUNT> javac *.java
This command assumes that the CLASSPATH environment variable contains all
of the packages used by the Account bean.
For the EJB server (AE) environment, the following finder logic is required
for each finder method (other than the findByPrimaryKey method) contained in
the home interface of an entity bean with CMP:
- The logic must be defined in a public interface named
NameBeanFinderHelper, where Name is the name of the
enterprise bean (for example, AccountBeanFinderHelper).
- The logic must be contained in a String constant named
findMethodNameWhereClause, where findMethodName is the
name of the finder method. The String constant can contain zero or more
question marks (?) that are replaced from left to right with the value of the
finder method's arguments when that method is invoked.
- Note:
- Encapsulating the logic in a String constant named
findMethodNameQueryString has been deprecated.
If you define the findLargeAccounts method shown in Figure 24, you must also create the AccountBeanFinderHelper interface
shown in Figure 7.
Figure 7. Code example: AccountBeanFinderHelper interface for the EJB server (AE)
...
public interface AccountBeanFinderHelper{
String findLargeAccountsWhereClause = "balance > ?";
}
|
The WebSphere Application Server Application Assembly Tool can be used to
create an EJB module. One or more enterprise beans can be placed in an
EJB module. The tool automatically creates the required deployment
descriptor for the module based on information specified by the user.
- Note:
- Before using the Application Assembly Tool, the WebSphere Common
Configuration Model (WCCM) MetaObject Facility (MOF) JAR files must be added
to your CLASSPATH environment variable.
To create an EJB module and corresponding deployment descriptor, use the
Create an EJB JAR wizard in the Application Assembly Tool. This wizard
prompts you to specify the following information for each enterprise bean to
be included in the module:
- The enterprise bean class, home interface class, and remote interface
class.
- The bean type (entity or session), and associated attributes (such as
persistence management type and primary key class for entity beans).
- Any environment variables to be associated with the enterprise
bean.
- References to another enterprise bean's home interface and to
resource factories.
- References to security roles for the enterprise bean.
The wizard also prompts you to specify the following application assembly
information for the module itself:
- General properties of the EJB module, such as the location of class files
needed for a client program to access the enterprise beans in the module and
the icons to be associated with the module.
- The deployable enterprise beans that the module will contain.
- Security roles used to access resources in the module.
- Transaction attributes for the enterprise bean methods.
Both bean and module information are used to create the deployment
descriptor. See the WebSphere InfoCenter and the online help for
details on how to use the Application Assembly Tool.
For entity beans with container-managed persistence (CMP), you must
store the bean's persistent data in one of the supported
databases. The Application Assembly Tool automatically generates SQL
code for creating database tables for CMP entity beans. The tool names
the database schema and table ejb.beanNamebeantbl, where
beanName is the name of the enterprise bean (for example,
ejb.accountbeantbl). If your CMP entity beans require complex
database mappings, it is recommended that you use VisualAge for Java to
generate code for the database tables. At run time, the WebSphere
Administrative Console displays a prompt asking whether you want to execute
the generated SQL code that creates the database table.
For entity beans with bean-managed persistence (BMP), you can
create the database and database table by using the database tools or use an
existing database and database table. Because entity beans with BMP
handle the database interaction, any database or database table name is
acceptable.
For more information on creating databases and database tables, consult
your database documentation and the online help for the WebSphere
Administrative Console.