Oracle WebLogic Server 12c: Creating and Using a Deployment Plan

<Do not delete this text because it is a placeholder for the generated list of "main" topics when run in a browser>

Purpose

This tutorial shows how to use the PlanGenerator utility to generate an initial deployment plan for an existing web application. The tutorial then shows how to edit the deployment plan and use the Oracle WebLogic Server 12c administration console to associate the plan with the application when it is redeployed.

Time to Complete

Approximately 1/2 hour

Overview

A deployment plan is an XML document used to define an application’s deployment configuration for a specific WebLogic Server environment, such as development, test, or production. A deployment plan resides outside of an application’s archive file and contains deployment properties that override an application’s existing Java Enterprise Edition and WebLogic Server deployment descriptors. Use deployment plans to easily change an application’s WebLogic Server configuration for a specific environment, without modifying existing deployment descriptors.

The weblogic.PlanGenerator utility is a Java-based command-line tool for developers who want to export portions of a WebLogic Server deployment configuration into a deployment plan file. This utility can generate a brand new plan, or can append to an existing one. This tutorial covers using that utility to generate a deployment plan. It then covers redeploying the web application with that plan by using the Oracle WebLogic Server 12c (12.1.1) administration console.

Software Requirements

The following is a list of software requirements:

Prerequisites

Before starting this tutorial, you should have completed the Oracle by Example tutorials titled Oracle WebLogic Server 12c: Installing WebLogic Server and Creating a Domain and Oracle WebLogic Server 12c: Configuring Managed Servers.

Deploying the Application

To deploy the supplied Java web application, perform the following steps:

.

If the administration server of the domain is not already running, it needs to be started. To start it, in a Terminal window, navigate to the domain directory, and enter the command:

$ ./startWebLogic.sh

 

When prompted for a username and password, enter the credentials of the domain administrator.

 

.

The managed server dizzy1 should also be running. If it is not already running, start it. In another Terminal window, navigate to the domain directory, then cd into the bin subdirectory. Enter the command:

$ ./startManagedWebLogic.sh dizzy1 http://host01.example.com:8001

This runs the script to start the managed server named dizzy1. Also notice the argument that gives the URL of the domain's administration server:
http://host01.example.com:8001.

Note: Use the host name and port of the administration server of your domain.

 

When prompted for a username and password, enter the credentials of the domain administrator.

 

.

Download the deploy_plan.zip file to the machine where your WebLogic Server domain and servers are. Extract the file contents to a local drive. In this tutorial, the files are extracted into the /home/oracle/apphome directory. This directory will be referred to as <APP_HOME> in later steps. The zip file contains two files:

  • hrapp.war
    A simple web application in an archive file
  • deploy_hrapp.py
    A WebLogic Scripting Tool (WLST) script used to deploy the web application

 

.

Open a new Terminal window and navigate to the /server/bin directory under the WebLogic installation directory. In this tutorial, that is:
/u01/app/oracle/Middleware/wlserver_12.1/server/bin

Then run the setWLSEnv.sh script as follows:

$ source setWLSEnv.sh

This will set the PATH and the CLASSPATH so the WLST deployment script can be executed.

 

.

Next navigate to the <APP_HOME> directory. In this tutorial, that directory is: /home/oracle/apphome.

Before running the supplied WLST script, deploy_hrapp.py, you may need to edit it. The first line of the script uses the connect() command. The first argument of that command is the domain administrator's username, the second argument is that user's password, and the third argument is the host and port of the administration server of the domain. Make sure the values for these arguments are correct for your domain before running this script.

Make any changes required to the script, and save the file.

 

.

Run the deploy_hrapp.py script to deploy the web application in the hrapp.war file and target it to the dizzy1 server. Do this by entering the following command:

$ java weblogic.WLST deploy_hrapp.py

 

You should see a message that the deploy operation has succeeded.

Note: You can ignore the warning about Context.close(). That warning is always displayed when running a WLST script and is not an issue.

Note: Do not close this Terminal window. You will use it again later.

 

.

To verify the deployment was successful, use the administration console. Open a web browser and enter its URL:
http://hostname:port/console

In this tutorial, that is: http://host01.example.com:8001/console

Note: Use the host name and port of the administration server of your domain.

On the Welcome screen, log in using the Username and Password entered to start the servers.

Under Domain Structure, click Deployments. Then in the Deployments table, find HRApp with the "Active" State.

 

.

To use the deployed application, in another web browser, enter the host and port for the dizzy1 managed server, followed by /HRApp.

In this tutorial, the URL entered is:
http://host01.example.com:8003/HRApp

 

Generating and Editing a Deployment Plan

To generate an initial deployment plan for the web application and then edit it, perform the following steps:

.

Return to the same Terminal window used to run the WLST script. Confirm that the current directory is still <APP_HOME>. In this tutorial, that is the /home/oracle/apphome directory.

Run the PlanGenerator tool on the hrapp.war file by entering this command:

$ java weblogic.PlanGenerator -all hrapp.war

 

Notice the message that the plan was saved to the file plan.xml. Also notice the message: "Saved configuration for application, hrapp.war."

 

.

Locate the <APP_HOME>/plan.xml file and edit it with a text editor.

 

.

Locate the following <variable> element:

<variable>
  <name>WeblogicWebApp_ContextRoots_xxxxxxxxxxxxxx</name>
  <value xsi:nil="true"></value>
</variable>

Note that the xxxxxxxxxxxxxx will actually be random digits.

 

.

Edit the <variable> element. First delete xsi:nil="true" from the <value> tag.

Then set the body of the <value> tag to: /hr.

When finished, the <value> tag should look like this:
<value>/hr</value>

 

.

Futher down in the file, locate the <variable-assignment> element with the same name as the <variable> element you just edited:

<variable-assignment>
  <name>WeblogicWebApp_ContextRoots_xxxxxxxxxxxxxx</name>
  <xpath>weblogic-web-app/context-root</xpath>
  <origin>planbased</origin>
</variable-assignment>

Once again the xxxxxxxxxxxxxx will actually be random digits.

 

.

Add a new <operation> child element to the <variable-assignment> element, as follows:

<variable-assignment>
  <name>WeblogicWebApp_ContextRoots_xxxxxxxxxxxxxx</name>
  <xpath>weblogic-web-app/context-root</xpath>
  <origin>planbased</origin>
  <operation>replace</operation>
</variable-assignment>

 

.

Save the file.

What this deployment plan does is override the context-root element in the WebLogic Server web application deployment descriptor, weblogic.xml. The new context root is /hr.

Updating the Application with the Deployment Plan

To update the deployed web application with this new deployment plan, perform the following steps:

.

Go back to the administration console. In the Change Center, click the Lock & Edit button.

 

.

Under Domain Structure, click Deployments.

 

.

Select the checkbox for the HRApp application, and click the Update button:

 

.

Click the Change Path button associated with the Deployment plan path.

 

.

Select the radio button for the new plan.xml file, and click Next.

If necessary, use the hyperlinks next to the Current Location field to navigate to the <APP_HOME> directory.

 

.

Select the radio button Redeploy this application using the following deployment files.

Then click Finish.

 

.

In the Change Center click the Activate Changes button.

 

The message "All changes have been activated. No restarts are necessary." is displayed.

 

.

Verify the new context root of the application. In a web browser enter the host and port for the dizzy1 managed server, followed by /hr.

In this tutorial, the URL entered is:
http://host01.example.com:8003/hr

Remember, previously the context root was /HRApp.

 

Summary

In this tutorial, you learned how to:

Resources

Credits

Hardware and Software Engineered to Work Together Copyright © 2011, Oracle and/or its affiliates. All rights reserved