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
- Preparing to Deploy to Oracle Application Server
- Deploying Web Application to Oracle Application Server
- Configuring Datasource on Oracle Application Server
- Configuring Datasource Connection on DB-VA
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.
- From the menu bar, select Tools > Object Relational Mapping (ORM) > Generate Code ... to open the Database Code Generation dialog box.
- Set Deploy To option from JBoss Application Server to Generic Application Server.
DB-VA helps you to select the corresponding Optional Jar files.
- Click OK to regenerate code.
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.
- Open the command prompt and change to the schoolsystem.war folder in the JBoss deploy folder.
- Execute jar to create a war file in command prompt.
The command to create a war file:
jar -cvf schoolsystem.war .
The schoolsystem.war file is created inside the schoolsystem.war folder
- Start the Oracle Application Server from system menu Start > Programs > Oracle Application Server 10g > Start ....
- 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.
- 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.
- In the OC4J home page, select the Application tab and click Deploy WAR file.
- 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.
- When you see the successfully deployed message, the web application is running on the Oracle Application Server.
- 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.
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.
- 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.
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.
- Edit ORACLE_HOME/j2ee/home/configure/data-sources.xml to add your datasource.
<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"
/>
- Go to the OC4J home page to restart OC4J, the MySQL datasource is running on the Oracle application server now.
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.
- From the menu bar, select Tools > Object Relational Mapping (ORM) > Generate Code ... to open the Database Code Generation dialog box.
- Select the Database tab and select the Connection option from JDBC to Datasource.
- Enter the following information to configure the datasource on Oracle Application Server
| 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
Click OK to regenerate the code.
- Modify the Web.xml file in schoolsystem.war\WEB-INF folder to add resource-ref to the datasource.
|
<resource-ref>
<res-ref-name>app/schoolsystem</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
|
- 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.
|
|
| Visual Paradigm International Limited |
| Website: |
www.visual-paradigm.com |
| E-mail: |
support@visual-paradigm.com |
|