Oracle by Example brandingCreate and Use a Deployment Plan in Oracle WebLogic Server

section 0Before You Begin

In this 15-minute tutorial, you will learn how to generate an initial deployment plan for an existing web application, edit the deployment plan, and then use the WebLogic Server Administration Console to redeploy your application with that plan.

Background

This tutorial is part of the Oracle WebLogic Server 12c series, and assumes that you have completed these tutorials, in this order:

A deployment plan is an XML document that you use 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.

This tutorial shows how to use the weblogic.PlanGenerator utility to generate a deployment plan. 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. With this utility, you can generate a new plan or append to an existing one. This tutorial covers deploying versioned applications that use the version name in the MANIFEST.MF file.

What Do You Need?

  • An installation of Oracle WebLogic Server 12c. See http://www.oracle.com/technetwork/middleware/weblogic/downloads/index.html.
  • A properly configured WebLogic Server domain containing an Administration Server and one Managed Server with the following settings:
    • Domain directory: /u01/domains/ExampleDomain with Managed Server, server1
    • Administration Server listen address and port number: localhost:7001
    • Managed Server, server1, listen address and port number: localhost:7003
  • An example application which is available for download here. This application archive contains three files:
    • hrapp.war, a simple web application in an archive file
    • deploy.py, a WebLogic Scripting Tool (WLST) script to deploy the web application
    • deploy.sh, a shell script to deploy the web application

Conventions

This tutorial uses the following conventions:

    Variable
     Value
    ORACLE_HOME Environment Variable  /u01/app/fmw
    DOMAIN_HOME Environment Variable  /u01/domains/ExampleDomain
    APP_HOME Environment Variable  /tmp/downloads/DeployPlan

section 1Deploy the Application

To deploy the supplied Java web application:

  1. If the Administration Server of the domain is not already running, start it. In a terminal window, navigate to the domain directory, and enter the command:
    $ cd ${DOMAIN_HOME}/
    $./startWebLogic.sh
    At the prompt, enter the Administrator user name and password that you specified when you created the domain.
  2. After the Administration Server is running, start the Managed Server, server1. In another terminal window, navigate to the DOMAIN_HOME/bin directory and enter the command:
    $./startManagedWebLogic.sh server1 http://localhost:7001
    Optionally, specify the host name and port of your domain's Administration Server in place of localhost:7001.
  3. Deploy the web application HRApp located in the hrapp.war file.
    • Open a new terminal window and navigate to the APP_HOME directory.
    • In this tutorial, we use the deploy.sh script to deploy the application. This script contains default values for the Administration Server URL, the target server to which you deploy the application, and the fully qualified path to your WebLogic Server installation directory. To override any of these default values, you must specify an appropriate parameter along with a valid value in the command line while deploying the application.

      For a complete list of supported parameters, run the deploy.sh script without any arguments:
        $./deploy.sh
    • Enter the command to deploy the application.
    • Note that the deploy.sh script uses the WebLogic Server Scripting Tool (WLST) to deploy the application.
      $./deploy.sh -a HRApp -p /tmp/downloads/DeployPlan/hrapp.war -U username -t server1
      In the command, enter the following values:
        • The name of the application, represented by -a.
        • The fully qualified path to the hrapp.war file, represented by -p.
        • The WebLogic Server Administrator user name, represented by -U.
        •  The target server, represented by -t. This is an optional argument. The deploy.sh script targets the application to the Administration Server by default. To target the application to any other server, you must specify the -t parameter along with the server name in the command line. In this tutorial, we target the application to the Managed Server, server1.
    • When prompted, enter the password for your WebLogic Server Administrator user name. For example:
        Weblogic Server administrator password required.
      Enter administrator password for user 'username':
      The application deploys successfully.
       >>>Deploying application from /tmp/downloads/DeployPlan/hrapp.war to targets 
       server1 (upload=false) ...
       <Sep 17, 2018 9:59:08 PM PDT> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating 
       deploy operation for application, HRAPP [archive: tmp/downloads/Deployplan/hrapp.war],
       to server1.> 
      .Completed the deployment of Application with status completed
      Current Status of your Deployment:
      Deployment command type: deploy
      Deployment State : completed
      Deployment Message : no message
      >>>Application HRApp deployed.
      
      Exiting WebLogic Scripting Tool.
      <Sep 17, 2018 9:59:12 PM PDT> <Warning> <JNDI> <BEA-050001> <WLContext.close()
      was called in a different thread than the one which it created.>
      Note: Ignore the warning about Context.close(). This warning displays when you run any WLST script.
      Do not close this terminal window as you will need it later.
  4. To verify that the deployment was successful, access the WebLogic Server Administration Console. Open a web browser and enter the URL:
      http://localhost:7001/console
    Optionally, you can specify the host name and port of your domain's Administration Server in place of localhost:7001.
  5. On the Welcome screen, enter the user name and password that you specified when you created the domain, and then click Login.
  6. In the left pane of the Console, under Domain Structure, select Deployments. In the Deployments table, verify that HRApp is in the Active State.
    Application deployment successful
    Description of the illustration deployments_table.png
  7. Access the deployed application in another browser window. Enter the host and port for the Managed Server, server1, followed by /HRApp. In this tutorial, the URL is:
      http://localhost.com:7003/HRApp
    Application Home page
    Description of the illustration app_page.png

section 2Generate and Edit a Deployment Plan

To generate an initial deployment plan for the web application and then edit it:

  1. Return to the same terminal window that you used to run the deploy.sh script. Ensure that the current directory is APP_HOME. Enter the command to run the PlanGenerator tool on the hrapp.war file:
    $ java weblogic.PlanGenerator -all hrapp.war
    Note: If you are using a new terminal window, then ensure that you run the source setWLSEnv.sh command before running the PlanGenerator tool. This command sets the PATH and the CLASSPATH for executing any WLST script.

    A message displays if the deployment plan is successfully generated for your application. Note that the deployment plan is saved to the plan.xml file in the APP_HOME directory.
    Saving plan to /tmp/downloads/DeployPlan/plan.xml...
    <Sep 18, 2018 2:41:37 AM PDT> <Info> <J2EE Deployment SPI> <BEA-260072> 
    <Saved configuration for application, hrapp.war>              
  2. Now, let's edit the deployment plan that you generated. Open the plan.xml file with a text editor and locate the <variable> element in the file.
        <variable>
          <name>WeblogicWebApp_ContextRoots_15362645019586</name>
          <value xsi:nil="true"></value>
        </variable>
  3. From the <value> tag in the <variable> element, delete xsi:nil="true". Then, change the value tag to the context root of the application /hr.
    The modified <value> tag should resemble:
        <variable>
          <name>WeblogicWebApp_ContextRoots_15362645019586</name>
          <value>/hr</value>
        </variable>
  4. Locate the <variable-assignment> element with the same name as the <variable> element that you edited.
    <variable-assignment>
            <name>WeblogicWebApp_ContextRoots_15362645019586</name>
            <xpath>/weblogic-web-app/context-root</xpath>
            <origin>planbased</origin>
       </variable-assignment>
  5. Add a new <operation> child element to the <variable-assignment> element, and set the value of the <operation> tag to replace as shown:
    <variable-assignment>
            <name>WeblogicWebApp_ContextRoots_15362645019586</name>
            <xpath>/weblogic-web-app/context-root</xpath>
            <origin>planbased</origin>
            <operation>replace</operation>
       </variable-assignment>
  6. Save the plan.xml file.

    This deployment plan overrides the context-root element in the WebLogic Server web application deployment descriptor, weblogic.xml. The new context root is /hr.

section 3Update the Application with the Deployment Plan

To update the deployed web application with the new deployment plan:

  1. Go back to the WebLogic Server Administration Console. In the Change Center, click Lock & Edit.
  2. Under Domain Structure, select Deployments.
    The Summary of Deployments page appears. A table that lists all the Java EE applications and standalone application modules currently installed on WebLogic Server appears in the right pane.
  3. Select the check box for the HRApp application, and click Update.
  4. From the Update Application Assistant window, click Change Path associated with the Deployment plan path.
  5. This is the Update Application Assistant Window to update the deployment path.
    Description of the illustration update_assistant.png
  6. Select the plan.xml option, and click Next.

    If necessary, use the hyperlink next to the Current Location field to navigate to the plan.xml directory.
    This is the Update Application Assistant window for plan.xml
    Description of the illustration plan_xml.png
  7. Select Redeploy this application using the following deployment files and click Next.
    This page shows the option to redeploy your application using the new deployment plan.
    Description of the illustration final_deploy.png
  8. Review your choices and click Finish.
  9. In the Change Center, click Activate Changes.

    The Console displays the message: All changes have been activated. No restarts are necessary.
  10. Verify the new context root of the application. In a web browser, enter the host and port for the Managed Server server1, followed by /hr.
    http://hostname:7003/hr
    Note that the previous context root /HRApp has changed to /hr.
    This is the application home page with the new context root.
    Description of the illustration final_app.png

more informationNext Steps

The WebLogic Server 12c collection contains a number of additional tutorials, covering a variety of topics. See the WebLogic Server 12c collection here for additional topics and content.