Previous Next
Deployment Guide for Java Chapter 6 - Deploying Enterprise Java Web Application to Oracle Application Server

Chapter 6 - Deploying Enterprise Java Web Application to Oracle Application Server

DB Visual ARCHITECT (DB-VA) provides different kinds of templates for user to generate Java code. The template will optimize the configuration of generated Java code and select jar files for different application servers or standalone Java application. DB-VA supports to generate configuration file to make the web application to use datasource connection to connect to database in the application server. In this chapter, we will deploy enterprise Java web application to an Oracle Application Server.

Introduction

This document is based on the Programmer's Guide for Java - Chapter 3 Developing Java Enterprise Web Application example to demonstrate the deployment steps on the Oracle application server. The Example of Programmer's Guide for Java - Chapter 3 is deployed on JBoss, so we will point out some important steps for user to modify to deploy on Oracle application server. Finally, we will configure the web application to use the datasource connection provide by the Oracle application server.

Preparing to Deploy to Oracle Application Server

Suppose you have downloaded the example of the Programmer's Guide for Java - Chapter 3 Developing Java Enterprise Web Application.

  1. From the menu bar, select Tools > Object Relational Mapping (ORM) > Generate Code ... to open the Database Code Generation dialog box.
  2. Figure 6.1 - To generate code
  3. Set Deploy To option from JBoss Application Server to Generic Application Server.
  4. Figure 6.2 - The Deploy to option

    DB-VA helps you to select the corresponding Optional Jar files.

    Figure 6.3 - select Optional Jar dialog
  5. Click OK to regenerate code.
  6. Copy the schoolsystem.war\src\ormmapping folder to schoolsystem.war\classes folder to make sure the configuration files are also updated.

Deploying Web Application to Oracle Application Server

Suppose you have installed the Oracle Application Server. In this example we will use Oracle Application Server 10g.

  1. Open the command prompt and change to the schoolsystem.war folder in the JBoss deploy folder.
  2. Execute jar to create a war file in command prompt.
  3. The command to create a war file:

    jar -cvf schoolsystem.war .

    The schoolsystem.war file is created inside the schoolsystem.war folder

    Figure 6.4 - The .war file
  4. Start the Oracle Application Server from system menu Start > Programs > Oracle Application Server 10g > Start ....
  5. Figure 6.5 - Start Oracle Application Server
  6. Go to the Application Server Control Console from system menu Start > Programs > Oracle - oracleas Enterprise Manager > Application Server Control Console or go to http://localhost:108100.
  7. Figure 6.6 - To open the Application Server Control Console
  8. Enter username and password to login. Select the J2EE Applications tab and then click home on OC4J Instance column to go to the OC4J Home page.
  9. Figure 6.7 - Application Server Control Console
  10. In the OC4J home page, select the Application tab and click Deploy WAR file.
  11. Figure 6.8 - To deploy WAR file
  12. Select the schoolsystem.war file location and enter the Application Name and Map to URL information. The Map to URL must be start with /. After that, click Deploy.
  13. Figure 6.9 - Enter the information of the WAR
  14. When you see the successfully deployed message, the web application is running on the Oracle Application Server.
  15. Figure 6.10 - The deploy successful message
  16. Use the Map to URL information to access your web application. Go to http://localhost/schoolsystem/index.html. You may have different port number for the application server.
  17. Figure 6.11 - The Student Page

Configuring Datasource on Oracle Application Server

The Oracle Application Server can provide a database for application to share the JDBC connection within server. The following steps teach you how to configure datasource on Oracle server. We will configure the MySQL datasource on Oracle server as an example.

  1. Copy the mysql.jar to ORACLE_HOME/j2ee/home/applib. The mysql.jar can be found at the DB-VA generate output folder/schoolsystem.war/WEB-INF/lib.
  2. The j2ee/home/applib directory contains libraries that are used by all applications on your application server. By dropping the MySQL JDBC drivers here, they can be used by all applications running on this OC4J instance.

  3. Edit ORACLE_HOME/j2ee/home/configure/data-sources.xml to add your datasource.
  4. <data-source
    class="com.evermind.sql.DriverManagerDataSource"
    name="MySQLDS"
    location="app/schoolsystem"
    xa-location="app/xa/schoolsystem"
    ejb-location="jdbc/MySQLDS"
    connection-driver="com.mysql.jdbc.Driver"
    username="root"
    password=""
    url="jdbc:mysql://localhost/schoolsystem"
    inactivity-timeout="30"
    />
  5. Go to the OC4J home page to restart OC4J, the MySQL datasource is running on the Oracle application server now.
  6. Figure 6.12 - Restart OC4J

Configuring Datasource Connection on DB-VA

You have setup the datasource on the Oracle and JNDI name called "app/schoolsystem" . You can configure the datasource connection to make the web application to use the datasource on the Server.

  1. From the menu bar, select Tools > Object Relational Mapping (ORM) > Generate Code ... to open the Database Code Generation dialog box.
  2. Figure 6.13 - To generate code
  3. Select the Database tab and select the Connection option from JDBC to Datasource.
  4. Figure 6.14 - Database Configuration
  5. Enter the following information to configure the datasource on Oracle Application Server
  6. Dialect org.hibernate.dialect.MySQLInnoDBDialect
    Datasource JNDI Name java:comp/env/app/schoolsystem
    JNDI Provider URL (empty)
    JNDI InitialContextFactory class (empty)
    User name (connect database user name)
    Password (connect database password)
    TransactionManagerLookup class org.hibernate.transaction. OC4JTransactionManagerLookup
    TransactionFactory class org.hibernate.transaction.JTATransactionFactory
    Table 6.1
    Figure 6.15 - Datasource Configuration
    Click OK to regenerate the code.
  7. Modify the Web.xml file in schoolsystem.war\WEB-INF folder to add resource-ref to the datasource.
  8. <resource-ref>
    <res-ref-name>app/schoolsystem</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
  9. Undeploy the schoolsystem web application on the Oracle application server and then repeat the step of Deploying Web Application on Oracle Application Server to deploy the web application. The web application run on the Oracle server will use the datasource connection to connect to database.

Previous Next
Visual Paradigm International Limited
Website: www.visual-paradigm.com
E-mail: support@visual-paradigm.com