Thursday, August 5, 2010

How to Use Weblogic WLST to Redeploy An Application, etc.

How to redeploy an application

Suppose the application is an ear file and it has already been deployed. Now you have made some changes and generated a new ear file. To redeploy the ear, you can do the following steps:

  1. Overwrite the old ear with the new ear file.
  2. Open wlst and perform the redeployment.

Suppose the name of the application is "myApp". The following is some trace of the wlst redeployment:
C:\bea921\weblogic92\common\bin>wlst

......

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands


wls:/offline> connect("userFoo","password","t3://localhost:7001");
Connecting to t3://localhost:7001 with userid userFoo

wls:/mydomain/serverConfig>

wls:/mydomain/serverConfig> progress=redeploy('myApp');
Redeploying application myApp ...
<Aug 5, 2010 11:45:06 AM EDT> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiat
ing redeploy operation for application, ......
>
..................Completed the redeployment of Application with status complete
d
Current Status of your Deployment:
Deployment command type: redeploy
Deployment State       : completed
Deployment Message     : no message
wls:/mydomain/serverConfig>

Note 1: The WLST redeploy command takes some optional arguments. You can use appPath to specify the name of the archive file or root of the exploded archive directory to be redeployed. My experiment is that if you put the new ear in a different location and use appPath to point to it, you will get the error message "Changing the source location is not allowed for a previously attempted deployment. Try deploying without specifying the source."
Note 2: The redeploy command will create a directory "config" under the current directory. In the example above, it will be C:\bea921\weblogic92\common\bin\config. If you do not have the right to create a sub-directory, you will get an error like "java.io.IOException: [J2EE Deployment SPI:260080]Unable to define application install directory at '/opt/bea/wl9.2.1/weblogic92/common/bin/config/deployments/...'. Directory could not be created or is a file.". If that is the case, you can go to a different directory where you can create a sub-directory and call the WLST command there.

Other WLST Commands for Deployment

You can also use WLST to start/stop/deploy/undeploy an application. The following is the simplified trace of performing these tasks.
C:\bea921\weblogic92\common\bin>wlst
wls:/offline> progress=stopApplication('myApp')
You will need to be connected to a running server to execute this command

wls:/offline> connect("userFoo","password","t3://localhost:7001");
Connecting to t3://localhost:7001 with userid userFoo ...

wls:/mydomain/serverConfig> progress=stopApplication('myApp');

..Completed the stop of Application with status completed

wls:/mydomain/serverConfig> progress=startApplication('myApp');
Starting application myApp.

......Completed the start of Application with status completed

wls:/mydomain/serverConfig> stopApplication('myApp');
Stopping application myApp.

.Completed the stop of Application with status completed

wls:/mydomain/serverConfig> undeploy('myApp', timeout=60000);
Undeploying application myApp ...

.Completed the undeployment of Application with status completed

wls:/mydomain/serverConfig> progress=deploy(appName='myApp',path='C:/home/deploy
/LOC/app/myApp.ear');

.........................Completed the deployment of Application with status completed

wls:/mydomain/serverConfig>

Note that you can undeploy the application without stopping it first.
It seems that when the ear is uploaded to weblogic, undeploy will delete the ear file. But if the ear is at outside location, undeploy will not delete the ear file. However, more investigation is needed for this.

Reference

http://download.oracle.com/docs/cd/E13222_01/wls/docs92/config_scripting/reference.html#wp1024321

1 comment:

  1. Thank you for the information. Can you guide towards a script where it performs these tasks.

    ReplyDelete