![]() |
![]() |
|
|
| |
Packaging EJBs for the WebLogic Server Container
The following sections describe how to package EJBs into a WebLogic Server container for deployment. They includes a description of the contents of a deployment package, including the source files, deployment descriptors, and the deployment mode.
Required Steps for Packaging EJBs
Packaging EJBs for deployment to WebLogic Server in an EJB container involves the following steps:
Reviewing the EJB Source File Components
To implement entity and session beans, use the following components:
WebLogic Server EJB Deployment Files
Use the following WebLogic Server deployment files to specify the deployment descriptor elements for the EJB.
The deployment files become part of the EJB deployment when the bean is compiled. The XML deployment descriptor files should contain the minimum deployment descriptor settings for the EJB. Once the file exists, it can later be edited using the instructions in Specifying and Editing the EJB Deployment Descriptors. The deployment descriptor files must conform to the correct version of the Document Type Definition (DTD) for each file you use. All element and sub element (attribute) names for each of the EJB XML deployment descriptor files are described in the file's Document Type Definition (DTD) file. For a description of each file, see the following sections.
ejb-jar.xml
The ejb-jar.xml file contains the Sun Microsystem-specific EJB DTD. The deployment descriptors in this file describe the enterprise bean's structure and declares its internal dependences and the application assembly information, which describes how the enterprise bean in the ejb-jar file is assembled into an application deployment unit. For a description of the elements in this file, see the JavaSoft specification.
weblogic-ejb-jar.xml
The weblogic-ejb-jar.xml file contains the WebLogic Server-specific EJB DTD that defines the caching, clustering, and performance behavior of EJBs. It also contains descriptors that map available WebLogic Server resources to EJBs. WebLogic Server resources include security role names and data sources such as JDBC pools, JMS connection factories, and other deployed EJBs. For a description of the elements in this file, see weblogic-ejb-jar.xml Document Type Definitions.
weblogic-cmp-rdbms.xml
The weblogic-cmp-rdbms.xml file contains the WebLogic Server-specific EJB DTD that defines container-managed persistence services. Use this file to specify how the container handles synchronizing the entity beans's instance fields with the data in the database. For a description of the elements in this file, see weblogic-cmp-rdbms- jar.xml Document Type Definitions.
Relationships Among the Deployment Files
Descriptors in weblogic-ejb-jar.xml are linked to EJB names in ejb-jar.xml, to resource names in a running WebLogic Server, and to persistence type data defined in weblogic-cmp-rdbms-jar.xml (for entity EJBs using container-managed persistence). The following diagram shows the relationship among the deployment files and WebLogic Server.
Figure 6-1 The relationship among the components of the deployment files.
Specifying and Editing the EJB Deployment Descriptors
You specify or edit EJB deployment descriptors by any of the following methods:
Creating the Deployment Files
You create the basic XML deployment files for the EJB that conforms to the correct version of the Document Type Definition (DTD) for each file. You can use an existing EJB deployment file as a template or copy one from the EJB examples in your WebLogic Server distribution:
wlserver\samples\examples\ejb20
Manually Editing EJB Deployment Descriptors
To edit XML deployment descriptor elements manually:
<max-beans-in-cache></max-beans-in-cache>
Using the EJB Deployment Descriptor Editor
To edit the EJB deployment descriptors in the WebLogic Server Administration Console:
You should see the following items that represent the EJB deployment descriptor files:
The current settings for the deployment descriptor file that you selected appear in the left pane. When you right-click on an item in the list, a dialog window for that item appears in the right pane.
You can change the settings in the dialog window to edit those deployment descriptors.
Here you can usually configure a new descriptor or customize your view of the existing settings. If an item in the table is underlined, you can click on it to display a dialog where you can change the settings.
Note: For more information on the EJB deployment descriptors, see either the online help in the Administration Console or weblogic-ejb-jar.xml Document Type Definitions, and weblogic-cmp-rdbms- jar.xml Document Type Definitions.
Setting WebLogic Server Deployment Mode
You deploy the enterprise archive file (EAR) or EJB to WebLogic Server by one of the following methods:
Using the Automatic Mode for Deployment
The automatic mode deployment option is the default. This feature automatically polls the application directory of the active server during startup and while the server is running, to determine whether an EJB deployment has changed. If a deployment has changed, it is automatically deployed when the server is polled. Use the applications directory for EJBs or EARs that you want to deploy in development mode. Once deployed, these EJBs/EARs are automatically persisted to the config.xml file.
WebLogic Server also checks the contents of applications every ten seconds to determine whether an EJB deployment has changed. If a deployment has changed, it is automatically redeployed using the dynamic deployment feature.
Automatically Deploying the EJB Examples
The EJB examples shipped with WebLogic Server are automatically deployed in the wlserver/config/applications directory.
Using the Production Mode for Deployment
The production mode deployment option turns off automatic deployment. When production deployment mode is enabled, applications specified in the config.xml file are deployed when the server is started.
To enable this mode, at the command line set the following to true:
-d production mode enabled true
For more information on this production mode, see "Starting the WebLogic Administration Server from the Command Line" in startstop.html of the Administration Guide.
Packaging EJBs into a Deployment Directory
The deployment process begins with a JAR file or a deployment directory that contains the compiled EJB interfaces and implementation classes created by the EJB provider. Regardless of whether the compiled classes are stored in a JAR file or a deployment directory, they must reside in subdirectories that match their Java package structures.
The EJB provider should also supply an EJB compliant ejb-jar.xml file that describes the bundled EJB(s). The ejb-jar.xml file and any other required XML deployment file must reside in a top-level META-INF subdirectory of the JAR or deployment directory. The following diagram shows the first stage of packaging the the EJB and the deployment descriptor files into a deployment directory or JAR file.
Figure 6-2 Packaging the EJB classes and deployment descriptors into a deployment directory
As is, the basic JAR or deployment directory cannot be deployed to WebLogic Server. You must first create and configure the WebLogic-specific deployment descriptor elements in the weblogic-ejb-jar.xml file, and add that file to the deployment directory or ejb.jar file. For more information on creating the deployment descriptor files, see WebLogic Server EJB Deployment Files.
If you are deploying an entity EJB that uses container-managed persistence, you must also add the WebLogic -specific deployment descriptor elements for the bean's persistence type. For WebLogic Server container-managed persistence (CMP) services, the file is generally named weblogic-cmp-rdbms-jar.xml. You require a separate file for each bean that uses CMP. If you use a third-party persistence vendor, the file type as well as its contents may be different from weblogic-cmp-rdbms-jar.xml; refer to your persistence vendor's documentation for details.
If you do not have any of the deployment descriptor files needed for your EJB, you must manually create one. The best method is to copy an existing file and edit the settings to conform to the needs of your EJB. Use the instructions in Specifying and Editing the EJB Deployment Descriptors to create the files.
ejb.jar file
You create the ejb.jar file with the Java Jar utility (javac). This utility bundles the EJB classes and deployment descriptors into a single Java ARchive (JAR) file that maintains the directory structure. The ejb-jar file is the unit that you deploy to WebLogic Server.
Compiling EJB Classes and Generating EJB Container Classes
For part of the process of building your deployment unit, you need to compile your EJB classes, add your deployment descriptors to the deployment unit, and generate the container classes used to access the deployment unit.
Container classes include both the internal representation of the EJB that WebLogic Server uses, as well as implementation of the external interfaces (home, local, and/or remote) that clients use.
The ejbc compiler generates container classes according to the deployment descriptors you have specified in WebLogic-specific XML deployment descriptor files. For example, if you indicate that your EJBs will be used in a cluster, ejbc creates special cluster-aware classes that will be used for deployment.
You can also use ejbc directly from the command line by supplying the required options and arguments. See ejbcfor more information.
The following figure shows the container classes added to the deployment unit when the JAR file is generated
Figure 6-3
Generating the EJB container classes
Once you have generated the deployment unit, you can designate the file extension as either a JAR, EAR, or WAR archive.
Loading EJB Classes into WebLogic Server
Classloaders in Weblogic Server are hierarchical. When you start WebLogic Server, the Java system classloader is active and is the parent of all subsequent classloaders that WebLogic Server creates. When WebLogic Server deploys an application, it automatically creates two new classloaders: one for EJBs and one for Web applications. The EJB classloader is a child of the Java system classloader and the Web application classloader is a child of the EJB classloader.
For more information on classloading, see "Classloader Overview" and "About Application Classloaders" in Developing WebLogic Server Applications.
Specifying an ejb-client.jar
WebLogic Server supports the use of ejb-client.jar files.
The ejb-client.jar contains the home and remote interfaces, the primary key class (as applicable), and the files they reference. WebLogic Server does not add files referenced in your classpath to ejb-client.jar. This enables WebLogic Server to add necessary custom classes to the ejb-client.jar without adding generic classes such as java.lang.String.
For example, the ShoppingCart remote interface might have a method that returns an Item class. Because this remote interface references this class, and it is located in the ejb-jar file, it will be included in the client jar.
You configure the creation of an ejb-client.jar file in the bean's ejb-jar.xml deployment descriptor file.When you compile the bean with ejbc, WebLogic Server creates the ejb-client.jar.
To specify an ejb-client.jar:
<ejb-client-jar>ShoppingCartClient.jar</ejb-client-jar>
$ java weblogic.ejbc <ShoppingCart.jar>
Container classes include both the internal representation of the EJB that WebLogic Server uses, as well as implementation of the external interfaces (home, local, and/or remote) that clients use.
External clients can include the ejb-client.jar in their classpath. Web applications would include the ejb-client.jar in their /lib directory.
Note: WebLogic Server classloading behavior varies, depending on whether or not the client is stand-alone. Stand-alone clients with access to the ejb-client.jar can load the necessary classes over the network. However, for security reasons, programmatic clients running in a server instance cannot load classes over the network.
Manifest Class-Path
Use the manifest file to specify that a JAR file can reference another JAR file. Standalone EJBs cannot use the Manifest Class-Path. It is only supported for components that are deployed within an EAR file. The clients should reference the client.jar in the classpath entry of the manifest file.
To use the manifest file to reference another JAR file:
The referenced JAR file is named using a URL relative to the URL of the referencing JAR file.
Class-Path: AAyy.jar BByy.jar CCyy.jar.
Note: The entry is a list of JAR files separated by spaces.
To place the home/remote interfaces for the EJB in the classpath of the calling component:
![]() |
![]() |
![]() |
|
Copyright © 2001 BEA Systems, Inc. All rights reserved.
|