Skip Headers

Oracle Application Server TopLink Application Developer's Guide
10g (9.0.4)

Part Number B10313-01
Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Go to previous page Go to next page

9
Packaging for Deployment

With your Oracle Application Server TopLink application built, you are ready to package and deploy the project to your enterprise. This chapter discusses:

This chapter discusses packaging and deployment from an OracleAS TopLink perspective. However, if you deploy your application to a J2EE container, you must configure elements of your application to enable OracleAS TopLink container support.

For more information, see also Appendix B, "Configuring OracleAS TopLink for J2EE Containers".

Introduction to Packaging and Deployment Concepts

This chapter introduces a basic approach to packaging that offers consistency across your projects, and the flexibility to work with projects of all kinds.

OracleAS TopLink Approach to Deployment

The OracleAS TopLink approach to deployment involves packaging application files into a single file, such as a Java archive (JAR) file, or an enterprise archive (EAR) file. This approach enables you to create clean and self-contained deployments that do not require significant file management.

After you create these files, you deploy the project.

OracleAS TopLink in an Enterprise Application

As an integral part of the enterprise application, OracleAS TopLink provides persistence and object-to-relational mapping functions. In most cases, the client does not interact with OracleAS TopLink directly; instead, clients access a client application that passes requests to OracleAS TopLink. As a result, there are two important steps to OracleAS TopLink deployment: make the packaged OracleAS TopLink application available; and add code to the client application to invoke OracleAS TopLink.

Road to Deployment

The goal of deployment is to provide the project to the client applications. Before you attempt to deploy an OracleAS TopLink application, complete the following:

  1. Build the project elements, including beans, classes, and datasources.

  2. Define the application mappings in the OracleAS TopLink Mapping Workbench.

  3. Build the application deployment files. Use the OracleAS TopLink Mapping Workbench and the OracleAS TopLink Sessions Editor to create the files.

  4. Package and deploy the application.

  5. Add code to the client application to enable it to access the OracleAS TopLink application.

XML Versus Java Source Deployment

You can deploy the application mappings that you define in the OracleAS TopLink Mapping Workbench with your application as an XML file or as a compiled Java class. The OracleAS TopLink Mapping Workbench supports exporting for both of these formats.

The more traditional approach to deployment is to export Java source files from the OracleAS TopLink Mapping Workbench. It requires you to recompile the resulting Java files.

XML deployment files offer better flexibility both before and after deployment, and are easier to troubleshoot if a problem occurs. Because of this, in most cases, you should deploy your project using XML files rather than Java source files.

Creating OracleAS TopLink Deployment Files

The OracleAS TopLink Mapping Workbench provides the ability to create deployment files from a OracleAS TopLink Mapping Workbench project. After you build a project, you have two options to create the deployment files:

XML deployment is the preferred method of deployment, because XML files are easier to deploy and troubleshoot than compiled Java files.

This section discusses:

XML Deployment Files

To deploy an OracleAS TopLink application, create a project file, in addition to one or more supporting files, as follows:

Related beans share the same ejb-jar.xml file, J2EE container-specific file, and toplink-ejb-jar.xml file.

For more information, see "Container-Managed Persistence Applications".

Project.xml File

The project.xml file is the core of your application. It contains the mappings and descriptors you define in the OracleAS TopLink Mapping Workbench, and also includes any named queries or finders associated with your project.

Because you must synchronize the project.xml file with the classes and database associated with your application, we recommend you not modify this file manually. The OracleAS TopLink Mapping Workbench ensures proper synchronization, and is the best way to make changes to the project. Simply modify the project in the OracleAS TopLink Mapping Workbench and redeploy the file project.xml file.

To redeploy a project.xml file, shut down and restart your OracleAS TopLink application.


Note:

Because the sessions.xml file includes the name of the project file, you can save the project file with a name other than project.xml; however, for clarity, this discussion assumes that the file has not been renamed.


In addition to generating the deployment XML from the OracleAS TopLink Mapping Workbench, you can use either of the following methods and use the DeploymentXMLGenerator API:


Note:

Before you use either method, ensure your the class path includes he <ORACLE_HOME>\toplink\config directory.


Sessions.xml File

The sessions.xml file provides a simple and flexible way to configure, modify, and troubleshoot the application database sessions. Because of these attributes, the sessions.xml file is the preferred way to configure an OracleAS TopLink session.

The OracleAS TopLink Sessions Editor is a graphical tool to build and edit the sessions.xml file, but you can also use a text editor.

For more information about the OracleAS TopLink Sessions Editor, see "Understanding the OracleAS TopLink Sessions Editor" in the Oracle Application Server TopLink Mapping Workbench User's Guide.

For more information, see "Configuring Sessions with the sessions.xml File".

Configuring the toplink-ejb-jar.xml File with the IBM WebSphere Server 4.0

The toplink-ejb-jar.xml file specifies all OracleAS TopLink-related information for an EJB entity bean deployment to a J2EE container. It includes several elements you use to configure the application.

The OracleAS TopLink deployment descriptor is included in the EJB JAR in the same META-INF directory as the ejb-jar.xml.

session

The session element contains settings for the entire project. The toplink-ejb-jar.xml file must include a session section, which includes the following XML elements:

For more information about the toplink-was-ejb-jar_904.dtd, see <ORACLE_HOME>\toplink\config\dtds.

Configuring the toplink-ejb-jar.xml File with the BEA WebLogic Server

The toplink-ejb-jar.xml file specifies all OracleAS TopLink-related information for an EJB entity bean deployment to a J2EE container. It includes several elements you use to configure the application.

The OracleAS TopLink deployment descriptor is included in the EJB JAR in the same META-INF directory as the ejb-jar.xml.

session

The session element contains settings for the entire project. The toplink-ejb-jar.xml file must include a session section, which may include the following XML elements:

Using Java Source Deployment Files

Although XML deployment is the preferred deployment method, you can also deploy your OracleAS TopLink project as Java source files. To deploy a project as Java source files, create your project, and export the Java source files from the OracleAS TopLink Mapping Workbench. After you generate the files, compile them with an integrated development environment (IDE). This more traditional deployment method results in OracleAS TopLink applications with the following characteristics:

In addition to generating the Java Source from the OracleAS TopLink Mapping Workbench, you can use either of the following methods and use the JavaSourceGenerator API:


Note:

Before you use either method, ensure your the class path includes he <ORACLE_HOME>\toplink\config directory.


XML Files for Java Deployment

As with an XML deployment, a Java source deployment requires the sessions.xml file (for non-EJB applications) or EJB deployment descriptor files (for EJB projects). Build these files the same way you do for an XML deployment, and deploy it with your project.

For more information, see "Sessions.xml File", and "Configuring the toplink-ejb-jar.xml File with the BEA WebLogic Server".

Configuring Additional Files for CMP Deployment

If you deploy your application to a J2EE container that implements Container-managed Persistence (CMP), you may have to configure additional files to support the deployment. This section discusses:

Configuring the ejb-jar.xml File

There is one ejb-jar.xml file for every JAR, although you can specify multiple beans in a single ejb-jar.xml file. The EJB specification you use determines the contents of this file.

Most IDEs provide facilities to create the ejb-jar.xml file. For more information about generating this file, see your IDE documentation.

If you build an EJB 2.0 application, the OracleAS TopLink Mapping Workbench can build the ejb-jar.xml file for you. Because the OracleAS TopLink Mapping Workbench can both read and write the ejb-jar.xml, you can either drive changes in the ejb-jar.xml file using the OracleAS TopLink Mapping Workbench:

For more information about managing the ejb-jar.xml file in the OracleAS TopLink Mapping Workbench, see the Oracle Application Server TopLink Mapping Workbench User's Guide.

Configuring the [J2EE-Container]-ejb-jar.xml

The contents of the [J2EE-Container]-ejb-jar.xml file depends on the container to which you deploy your beans. To create this file, use the tools that accompany your container.

In most cases, the [J2EE-Container]-ejb-jar.xml file integrates with OracleAS TopLink without revision. However, when you deploy to a WebLogic Server container, modify the weblogic-ejb-jar.xml. The topics in this section explore the required modifications.

Configuring the [J2EE-Container]-ejb-jar.xml File for BEA WebLogic

To deploy to a BEA WebLogic Server, modify the webLogic-ejb-jar.xml file. Within that file, each bean must have a persistence-descriptor entry with subentries, as follows:

Unsupported weblogic-ejb-jar.xml File Tags

The weblogic-ejb-jar.xml file includes several tags that OracleAS TopLink either does not support or does not require:

Packaging an OracleAS TopLink Application

The OracleAS TopLink approach to deployment involves packaging application files into a single file, such as a JAR file, or an EAR file. Each of the deployment strategies discussed in this section use this approach. The nature of the application also influences the approach you take to deploying the project. This section illustrates deployment strategies for:

Java Applications

The OracleAS TopLink application does not use a J2EE container for deployment. Instead, it relies on OracleAS TopLink mechanisms to provide functionality and persistence. The key elements of this type of application are the lack of a J2EE container and the fact that you deploy the application by placing the application JAR on the class path.

Packaging the Java Application

You deploy Java applications simply by placing them on the class path. To follow the standard OracleAS TopLink approach of encapsulating applications in an archive, deploy the application in a JAR file, as follows:

  1. Place the sessions.xml and project.xml files in the root of the JAR.

  2. Include all mapped classes and any required helper classes in the JAR.

  3. Place the completed JAR on the class path.

Deploying the Application to a Client

Build the JAR and place it on the class path. Include the following Java code in your client application to access the OracleAS TopLink application from a client:

Session mysession = SessionManager.getManager().getSession("[SESSION-NAME]");

Java Server Pages and Servlets Applications

Many designers build OracleAS TopLink applications that use Java server pages (JSPs) and Java servlets. This type of design generally supports Web-based applications.

Packaging Applications with JSPs and Servlets

When you build an application to deploy to the Web, package the application components in separate archives based on function. You can then assemble the separate archive files in a single deployment archive file.

The final deployment archive is an EAR file. If your client application includes application XML files, store those files in the \meta-inf\ directory of the EAR. In addition, the EAR contains the following archive files:

A Domain JAR File

The domain JAR contains the OracleAS TopLink files and domain objects required by the application, including:

When you create the JAR file, the JAR building utility automatically creates a directory structure within the JAR. Ensure that the sessions.xml file and the project.xml file (or project.class file) appear at the root of the JAR file. Also ensure that the class directory structure starts at the root of the JAR.

A Web Archive (WAR) File

The WAR file contains the Web application files, including:

To complete the WAR file, modify the manifest.mf file (located in the \meta-inf directory) to include a reference to the domain JAR file. The standard manifest is generally empty except for the header and two carriage returns.

Example 9-1 illustrates how to add a class path attribute.

Example 9-1 Modified manifest.mf File

Manifest-Version: 1.0
Created-By: 1.3.1 (Sun Microsystems Inc.)
// Add the following line
Class-Path: [Domain-Archive-Name].jar
// Two carriage returns to complete the file
[CR]
[CR]

Deploying the Application to a Client

After you build the WAR and JAR files, build them into an EAR file for deployment. To deploy the EAR to your JSP servlet server, copy the EAR to a well-known directory. You may also need to use server-specific deployment tools. For more information, see the server documentation.

Include the following Java code in your client application to access the OracleAS TopLink application from a client:

Session s = SessionManager.getManager().getSession("[SESSION-NAME]",[classloader]);

In most cases, [classloader] represents the class loader from the current thread context, specified as follows:

    Thread.current().getContextClassLoader()

However, if your J2EE container does not support using this class loader, you can substitute the class loader from the current class, as follows:

    this.getClass().getLoader()


Note:

Oracle Application Server Containers for J2EE supports the use of the class loader from the current thread.


Session Bean Applications

Session beans generally model a process, operation, or service and as such are not persistent. You can build OracleAS TopLink applications that wrap interaction with OracleAS TopLink in session beans. Session beans execute all OracleAS TopLink-related operations on behalf of the client.

This type of design leverages JTS and externally managed transactions, but does not incur the overhead associated with CMP applications. Session bean applications also scale and deploy easily.

Packaging Applications with Session Beans

When you build an application to deploy to the Web, package the application components in separate archives based on function. You can then assemble the separate archive files in a single deployment archive file.

The final deployment archive is an EAR file. If your client application includes application XML files, store those files in the \meta-inf\ directory of the EAR. In addition, the EAR contains the following archive files

A Domain JAR File

The domain JAR contains the OracleAS TopLink files and domain objects required by the application, including:

When you create the JAR file, the JAR building utility automatically creates a directory structure within the JAR. Ensure that the sessions.xml file and the project.xml file (or project.class file) appear at the root of the JAR file. Also ensure that the class directory structure starts at the root of the JAR.

An EJB JAR File

The EJB JAR file specifically services the session beans in the application. It includes:

In addition, modify the manifest.MF file, found in the \meta-inf\ directory, to include a reference to the domain JAR. The standard manifest is generally empty except for the header and two carriage returns.

Example 9-1 illustrates how to add a class path attribute.

A WAR File

The WAR file contains the Web application files, including:

In addition, modify the manifest.MF file, found in the \meta-inf\ directory, to include a reference to the domain JAR. The standard manifest is generally empty except for the header and two carriage returns.

Example 9-1 illustrates how to add a class path attribute.

Deploying the Application to a Client

After you build the WAR and JAR files, build them into an EAR file for deployment. To deploy the EAR to your J2EE server, copy the EAR to a well-known directory. You may also need to use server-specific deployment tools. For more information, see the server documentation.

Include the following Java code in your client application to access the OracleAS TopLink application from a client:

Sessions = SessionManager.getManager().getSession("[SESSION-NAME]",[classloader]);

In most cases, [classloader] represents the class loader from the current thread context, specified as follows:

    Thread.current().getContextClassLoader()

However, if your J2EE container does not support using this class loader, you can substitute the class loader from the current class, as follows:

    this.getClass().getLoader()


Note:

Oracle Application Server Containers for J2EE supports the use of the class loader from the current thread.


Container-Managed Persistence Applications

Many applications leverage the persistence mechanisms a J2EE container offers. OracleAS TopLink provides full support for this type of application.

The final deployment archive is an EAR file. If your client application includes application XML files, store those files in the \meta-inf\ directory of the EAR. In addition, the EAR contains the following archive files:

An EJB JAR file

The EJB JAR file specifically services the EJB entity beans in the application. It includes:

Store the following XML files in the \meta-inf\ directory:

A WAR File

The WAR file contains the Web application files, including:

General Deployment

After you build the WAR and JAR files, build them into an EAR file for deployment. To deploy the EAR to your J2EE server, copy the EAR to a well-known directory. You may also need to use server-specific deployment tools. For more information, see the server documentation.

Deploying the Application to BEA WebLogic Server

OracleAS TopLink CMP support includes integration for BEA WebLogic Server. To enable OracleAS TopLink CMP for WebLogic entity beans, use the WebLogic EJB Compiler (ejbc) to compile the EJB JAR, as follows:

When you run ejbc:

For more information about running ejbc, see the BEA WebLogic documentation.

Troubleshooting ejbc

When you start ejbc, it processes the data in a series of stages. If errors occur while running ejbc, attempt to determine which stage causes the problem. Common problems include:

Deploying the Application to IBM WebSphere 4.x Server

OracleAS TopLink CMP support includes an integration for IBM WebSphere 4.x Server. Use the following procedure to deploy your application to WebSphere:

  1. Use the OracleAS TopLink Deploy Tool for WebSphere to compile the EJB JAR file.

    For more information, see "Deploy Tool for WebSphere Server".

  2. Start the WebSphere Administration Server.

  3. Start the Administrator's Console and deploy the compiled JAR.

    For more information about deploying the JAR, see the IBM WebSphere documentation.


    Note:

    When you deploy an application that contains an entity bean, set up a datasource and associate it with the bean. For more information about how to create and associate datasources, see the IBM WebSphere documentation.


It is not necessary to deploy the EJB JAR in WSAD, because deployment is carried out using the Deploy Tool (see "Deploy Tool for WebSphere Server").

Starting the Entity Bean

You can start the bean in either the WebSphere Application Server or in WSAD.

To start the bean in IBM WebSphere Application Server:
  1. Select the application that contains the entity beans.

  2. Right click and choose Start.

    A message dialog appears if the bean starts successfully. If an error occurs, consult Appendix C, "Error Codes and Messages" for troubleshooting information.

To start the bean in WSAD:
  1. In WSAD, right click the EJB project and choose Run on Server.

  2. To view the status of the process, open the Console tab of the Server view.

Bean-Managed Persistence Applications

OracleAS TopLink enables developers to leverage bean-managed persistence in their OracleAS TopLink applications. The OracleAS TopLink base class for the BMP entity beans implements the methods required for the EJB specification.

For more information about OracleAS TopLink BMP support, see "Overview of Bean-Managed Persistence".

The final deployment archive is an EAR file. If your client application includes application XML files, store those files in the \meta-inf\ directory of the EAR. In addition, the EAR contains the following archive files

An EJB JAR file

The EJB JAR file specifically services the EJB entity beans in the application. It includes:

Store the following XML files as follows:

A WAR File

The WAR file contains the Web application files, including:

Deploying the Application

After you build the WAR and JAR files, build them into an EAR file for deployment. To deploy the EAR to your J2EE server, copy the EAR to a well-known directory. You may also need to use server-specific deployment tools. For more information, see the server documentation.

Hot Deployment of EJBs

Many J2EE containers support hot deployment, a feature that enables you to deploy EJBs on a running server. Hot deployment allows you to:

When you take advantage of hot deployment, consider the following:

The client receives deployment exceptions when attempting to access undeployed or re-deployed bean instances. The client application must catch and handle the exceptions.

For more information about hot deployment, see the J2EE container documentation.


Go to previous page Go to next page
Oracle
Copyright © 2000, 2003 Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index