| ||
Once the J2EE application has been created and packaged within an EAR file, it's time to deploy it. In this chapter we'll show you how to deploy to the OC4J 9.0.4 standalone container. This isn't the full- size 10g AS product, but rather the smaller OC4J container. We cover the full size 10g AS product in Chapters 1521 with a deployment covered in Chapter 18.
Deploying to a standalone OC4J container allows you to either package and deploy an EAR file or to have OC4J reference an expanded directory structure without the EAR file. Since the expanded directory structure is only applicable to the standalone OC4J instance (not the 10g AS server), we'll focus on deploying EAR files.
To deploy an EAR file manually to an OC4J standalone container, you'll need to use the java jar admin.jar command. We'll use the Petstore example application for the sample. The steps are as follows :
Log in to the server as the software owner. Since you're deploying to a Linux server where you have a standalone OC4J installation, log in as oracle , as follows:
$ id uid=500(oracle) gid=501(dba) groups=501(dba),100(users)
Verify the environment and OC4J version, as shown here:
$ echo $ORACLE_HOME /u01/app/oracle/product/9.0.4oc4j $ cd $ORACLE_HOME/j2ee/home $ java -jar oc4j.jar -version Oracle Application Server Containers for J2EE 10g (9.0.4.0.0) (build 040317.1838) $
Copy or use FTP to move the EAR file from the developer to the $ORACLE_HOME/j2ee/home directory. In this case, you're deploying petstore.ear , as follows:
$ cp /home/oracle/deployments/ftp_dir/petstore.ear . $ ls -l petstore.ear -rw-r--r-- 1 oracle dba 1234968 May 27 20:36 petstore.ear $
Deploy the new application using the deploy option to java jar admin.jar . This will create a new directory structure for the application, as shown here:
$ java -jar admin.jar ormi://192.168.1.11:11888 admin tigerpassword -deploy -file petstore.ear -deploymentName petstore 04/05/27 20:36:08 Notification ==> Application Deployer for petstore STARTS [ 2004-05-27T20:36:08.718EST ] 04/05/27 20:36:08 Notification ==> Undeploy previous deployment 04/05/27 20:36:08 Notification ==> Copy the archive to /u01/app/oracle/product/9.0.4oc4j/j2ee/home/applications/petstore.ear ... Notification ==> Initialize petstore begins... Notification ==> Initialize petstore ends... Notification ==> Application Deployer for petstore COMPLETES [ 2004-05-27T20:36:18.010EST ] $
In the previous sample, you used the java jar admin.jar command to deploy the application for the first time. You've configured the OC4J instance to use a nonstandard RMI port of 11888, and the IP is 192.168.1.11 so you should use ormi://192.168.1.11:11888 . The username is admin and the password is tigerpassword . You can use the deploy flag followed by file , and the EAR file we you're deploying, called petstore.ear . Finally, you give the new application a deployment name with -deploymentName petstore .
For security it's often advisable to change the default ports of your application server. Additionally, if software is already installed on a server that already uses those ports, you must change the ports of newer software to avoid port conflicts.
To change the default ports of OC4J standalone, edit the following files located in $ORACLE_HOME/j2ee/home/config .
$ vi rmi.xml <rmi-server port="11888" > $ vi jms.xml <jms-server port="11777"> $ vi http-web-site.xml Change in 2 locations <web-site host="localhost" port="11999" <web-site port="11999" display-name="Oracle9iAS Containers for J2EE HTTP Web Site">
Here you changed RMI to use 11888, JMS to use 11777, and HTTP to use 11999.
The deployment will create a petstore directory containing a petstore.war file (extracted from petstore.ear ) in the $ORACLE_HOME/j2ee/home/applications and application-deployments directories, as follows:
$ ls applications application-deployments application-deployments: default petstore applications: admin_ejb.jar admin_web.war dms dms0 dms0.war dms.war petstore petstore.ear $
Bind the newly deployed Petstore application to the /petstore URI using the bindWebApp flag, as shown here:
$ java -jar admin.jar ormi://192.168.1.11:11888 admin tigerpassword -bindWebApp petstore petstore http-web-site /petstore 04/05/27 20:38:58 Web-App default:defaultWebApp (0.0.0.0/0.0.0.0:11999/) started... 04/05/27 20:38:58 Building Application TagLibrary Persistent Cache for defaultWebApp 04/05/27 20:38:58 Done getting application current resources ... 04/05/27 20:38:58 Done persisting cache 04/05/27 20:38:58 Found 0 listeners $
Access the application, using the /petstore binding, at the following URL: http://mike.wessler.name:11999/petstore/ .
If you need to undeploy (remove) an application, use the following undeploy flag:
$ java -jar admin.jar ormi://192.168.1.11:11888 admin tigerpassword -undeploy petstore 04/05/27 20:54:56 Notification ==> Application UnDeployer for petstore STARTS [ Thu May 27 20:54:56 EST 2004 ] 04/05/27 20:54:56 Web-App default:defaultWebApp (0.0.0.0/0.0.0.0:11999/) started... ... 04/05/27 20:54:57 Notification ==> Application UnDeployer for petstore COMPLETES [ Thu May 27 20:54:57 EST 2004 ] $
The application has now been undeployed. Checking the $ORACLE_HOME/j2ee/home/applications and application-deployments directories shows that the Petstore application has been removed, as follows:
$ ls applications application-deployments application-deployments: default applications: admin_ejb.jar admin_web.war dms dms0 dms0.war dms.war $
The application can be deployed again by following steps 4 and 5.
As you saw earlier, deployment is a two-step process. First, the application is deployed using the deploy option to java jar admin.jar . This will create a new directory structure for the application under the $ORACLE_HOME/j2ee/home/applications and application-deployments subdirectories. Next, you bound the application to a URI using the -bindWebApp flag of javajar admin.jar .
Although the deployment requires two commands by the deployer, the following are several actions that occur behind the scenes:
First, the EAR file is opened and the application.xml file is read.
Next, each deployment descriptor for each included module (such as web.xml for web modules) is read. Any parameter not listed in the deployment descriptors will have the default values applied.
The application modules are created within the $ORACLE_HOME/j2ee/home/application-deployments directory. The $ORACLE_HOME/j2ee/home/application is also written. We cover the details of these directories in the "Directory Descriptions" section.
The global configuration file $ORACLE_HOME/j2ee/home/config/server.xml has the application added to it.
The global configuration file $ORACLE_HOME/j2ee/home/config/http-web-site.xml has the URI for the application bound to it.
Memory is initialized with the application and it's ready to be executed.
At this point the application can be executed because it has been deployed and bound.
Although the applications and application-deployments directories are specific to the application (not the global server), there are differences in content and purpose for each directory.
The applications directory is used to hold the exploded EAR file. This is where you will find the JARs, HTML, and JSPs of an application. It will also contain the EAR file that was deployed, as shown here:
$ ls -l $ORACLE_HOME/j2ee/home/applications total 1768 -rw-rw-r-- 1 oracle dba 12399 Mar 17 13:33 admin_ejb.jar -rw-rw-r-- 1 oracle dba 49665 Mar 17 13:33 admin_web.war drwxr-xr-x 4 oracle dba 4096 Mar 17 13:36 dms drwxr-xr-x 4 oracle dba 4096 Mar 17 13:36 dms0 -rw-rw-r-- 1 oracle dba 787 Mar 17 13:36 dms0.war -rw-rw-r-- 1 oracle dba 811 Mar 17 13:36 dms.war drwxr-xr-x 4 oracle dba 4096 May 27 21:01 petstore -rw-r--r-- 1 oracle dba 1234968 May 27 21:01 petstore.ear $
In the previous sample, you can see the petstore.ear file and a petstore directory. Within the petstore directory, you can see the files that were contained in the petstore.ear file, as shown here:
$ ls -l $ORACLE_HOME/j2ee/home/applications/petstore total 1364 -rw-r--r-- 1 oracle dba 67397 May 27 21:01 customerEjb.jar -rw-r--r-- 1 oracle dba 14997 May 27 21:01 inventoryEjb.jar -rw-r--r-- 1 oracle dba 7879 May 27 21:01 mailerEjb.jar drwxr-xr-x 2 oracle dba 4096 May 27 21:01 META-INF -rw-r--r-- 1 oracle dba 22273 May 27 21:01 personalizationEjb.jar drwxr-xr-x 7 oracle dba 4096 May 27 21:01 petstore -rw-r--r-- 1 oracle dba 266619 May 27 21:01 petstoreEjb.jar -rw-r--r-- 1 oracle dba 941693 May 27 21:01 petstore.war -rw-r--r-- 1 oracle dba 23796 May 27 21:01 shoppingcartEjb.jar -rw-r--r-- 1 oracle dba 18314 May 27 21:01 signonEjb.jar $
The files include EJB JAR files, the petstore.war file contains web modules, and the META-INF directory contains the application.xml file, as shown here:
$ ls -l $ORACLE_HOME/j2ee/home/applications/petstore/META-INF total 8 -rw-r--r-- 1 oracle dba 880 May 27 21:01 application.xml -rw-r--r-- 1 oracle dba 23 May 27 21:01 MANIFEST.MF $
You can also see an additional petstore subdirectory located in $ORACLE_HOME/j2ee/home/applications/petstore . The web component contents of the petstore.war file is located in this directory, as follows:
$ ls -l petstore total 200 -rw-r--r-- 1 oracle dba 613 Jun 4 17:29 accountcreationsuccess.jsp -rw-r--r-- 1 oracle dba 576 Jun 4 17:29 accountupdatesuccess.jsp -rw-r--r-- 1 oracle dba 1973 Jun 4 17:29 addressform.html -rw-r--r-- 1 oracle dba 262 Jun 4 17:29 annotated-index.html ... drwxr-xr-x 2 oracle dba 4096 Jun 4 17:29 images -rw-r--r-- 1 oracle dba 2444 Jun 4 17:29 index.html -rw-r--r-- 1 oracle dba 475 Jun 4 17:29 index.jsp drwxr-xr-x 2 oracle dba 4096 Jun 4 17:29 ja drwxr-xr-x 2 oracle dba 4096 Jun 4 17:29 META-INF -rw-r--r-- 1 oracle dba 1117 Jun 4 17:29 missingformdata.jsp -rw-r--r-- 1 oracle dba 1429 Jun 4 17:29 topindex.jsp drwxr-xr-x 7 oracle dba 4096 Jun 4 17:29 WEB-INF $
The $ORACLE_HOME/j2ee/home/application-deployments directory contains the application configuration files and compiled code for execution. It's also the directory structure where OC4J-specific orion-X.xml files will be found, as follows:
$ ls -l $ORACLE_HOME/j2ee/home/application-deployments/petstore total 48 -rw-r--r-- 1 oracle dba 200 May 28 21:26 application.log drwxr-xr-x 2 oracle dba 4096 May 27 21:01 customerEjb.jar drwxr-xr-x 2 oracle dba 4096 May 27 21:01 inventoryEjb.jar -rw-r--r-- 1 oracle dba 615 May 27 21:01 jazn-data.xml drwxr-xr-x 2 oracle dba 4096 May 27 21:01 mailerEjb.jar -rw-r--r-- 1 oracle dba 1351 May 27 21:01 orion-application.xml drwxr-xr-x 2 oracle dba 4096 May 27 21:01 personalizationEjb.jar drwxr-xr-x 3 oracle dba 4096 May 27 21:06 petstore drwxr-xr-x 2 oracle dba 4096 May 27 21:01 petstoreEjb.jar -rw-r--r-- 1 oracle dba 215 May 27 21:01 principals.xml drwxr-xr-x 2 oracle dba 4096 May 27 21:01 shoppingcartEjb.jar drwxr-xr-x 2 oracle dba 4096 May 27 21:01 signonEjb.jar $
The configuration files are jazn-data.xml, orion-application.xml , and principals.xml . Notice that the *.jar are actually directories and not physical files, as shown here:
$ ls -l customerEjb.jar total 52 -rw-r--r-- 1 oracle dba 45921 May 27 21:01 deployment.cache -rw-r--r-- 1 oracle dba 1577 May 27 21:01 orion-ejb-jar.xml $
In this case, they contain deployment.cache and orion-ejb-jar.xml files.
To force an automatic redeployment of the application, you can remove the application-specific subdirectories under applications and application-deployments . This is shown in the following procedure.
Shut down the OC4J instance, as follows:
$ java -jar admin.jar ormi://mike.wessler.name:11888 admin tigerpassword shutdown
Remove the $ORACLE_HOME/j2ee/home/application-deployments/ application_name that's specific to the application you want to redeploy, as shown here:
$ rm -rf $ORACLE_HOME/j2ee/home/application-deployments/petstore
Remove the $ORACLE_HOME/j2ee/home/application/ application_name that's specific to the application you want to redeploy, as follows:
$ rm -rf $ORACLE_HOME/j2ee/home/applications/petstore
Notice that you leave the EAR for the application. It's this file that's used for the redeployment, as shown here:
$ ls -l $ORACLE_HOME/j2ee/home/applications/petstore.ear -rw-r--r-- 1 oracle dba 1234968 May 27 21:01 /u01/app/oracle/product/9.0.4oc4j/j2ee/home/applications/petstore.ear
Restart the OC4J instance. The application will automatically redeploy, as follows:
$ java -jar oc4j.jar -config config/server.xml -verbosity 10 -err log/out.log
During startup you can see that OC4J automatically deploys the application using the petstore.ear file, as shown here:
04/06/04 17:29:47 Auto-unpacking /u01/app/oracle/product/9.0.4oc4j/j2ee/home/applications/petstore.ear... done. 04/06/04 17:29:47 Auto-unpacking /u01/app/oracle/product/9.0.4oc4j/j2ee/home/applications/petstore/petstore.war... done. 04/06/04 17:29:48 Auto-deploying petstore (New server version detected)... ...
The applications and application-deployment directories that you deleted have been created, as follows:
$ ls $ORACLE_HOME/j2ee/home/application*/petstore* /u01/app/oracle/product/9.0.4oc4j/j2ee/home/applications/petstore.ear /u01/app/oracle/product/9.0.4oc4j/j2ee/home/application-deployments/petstore: application.log jazn-data.xml personalizationEjb.jar principals.xml customerEjb.jar mailerEjb.jar petstore shoppingcartEjb.jar inventoryEjb.jar orion-application.xml petstoreEjb.jar signonEjb.jar /u01/app/oracle/product/9.0.4oc4j/j2ee/home/applications/petstore: customerEjb.jar mailerEjb.jar personalizationEjb.jar petstoreEjb.jar shoppingcartEjb.jar inventoryEjb.jar META-INF petstore petstore.war signonEjb.jar $
The application is again accessible via the following URL: http://mike.wessler.name:11999/petstore/ .
| ||