Saturday, September 14, 2013

Redeploy webapps through command line

Any function that can be done through the Weblogic admin console can be done through command-line equivalents. 

Using weblogic.Deployer Utility

To use the weblogic.Deployer utility:

   1. Set up your local environment so that WebLogic Server classes are in your system CLASSPATH and the JDK is available. You can use the setenv script located in your server's /bin directory to set the CLASSPATH.
   2. Use the following command syntax:

          % java weblogic.Deployer [options] [actions] [file(s)]


Here are the examples that can be seen by issuing the command java weblogic.Deployer -examples:
Deploy application on admin server:
java weblogic.Deployer -adminurl url -username username -password password
-name myapp -deploy c:/myapps/myapp.ear

Deploy individual modules in application to different targets:
java weblogic.Deployer -adminurl url -username username -password password
-name myapp -targets mywar@webserver,myjar@ejbserver -deploy
c:/myapps/myapp.ear

Undeploy application from specified targets:
java weblogic.Deployer -adminurl url -username username -password password
-name myapp -undeploy -targets server1,server2..

Redeploy application on current targets:
java weblogic.Deployer -adminurl url -username username -password password
-name myapp -redeploy

Redeploy individual module in an application:
java weblogic.Deployer -adminurl url -username username -password password
-name myapp -redeploy -targets moduleA@serverA,moduleA@serverB

Partially redeploy, for example, to update a JSP in a exploded webapp:
java weblogic.Deployer -adminurl url -username username -password password
-name myapp -redeploy mywar/index.jsp

        The path of JSP to be updated is relative to the root of the
        application. If a directory is specified the entire subtree is updated.

Multiple servers sharing the same physical deployment:
java weblogic.Deployer -adminurl url -username username -password password
-name myapp -targets server1,server2 -nostage -deploy c:/myapps/myapp.ear

        The -nostage option indicates that the application is available
        on all target servers at the same path and hence server should not copy
        files to the managed servers.

Full documentation on this tool is available at:
http://edocs.beasys.com/wls/docs70/programming/deploying.html

Solution

To achieve the proper environment setup, I started with the script startManagedWeblogic.sh. I removed the last line that does actual Java command and replaced it with this:
"$JAVA_HOME/bin/java" weblogic.Deployer -username $WLS_USER -password $WLS_PW -name alrs -verbose -redeploy
"$JAVA_HOME/bin/java" weblogic.Deployer -username $WLS_USER -password $WLS_PW -name cew -verbose -redeploy
"$JAVA_HOME/bin/java" weblogic.Deployer -username $WLS_USER -password $WLS_PW -name springglossary -verbose -redeploy
The script generates this output when run successfully on development:
pitblade:II:root: > ./redeployPoolApps.sh
Initiated Task: [8] [Deployer:149026]Redeploy application alrs on myserver.
Task 8 completed: [Deployer:149026]Redeploy application alrs on myserver.
Deployment completed on Server myserver

Initiated Task: [9] [Deployer:149026]Redeploy application cew on myserver.
Task 9 completed: [Deployer:149026]Redeploy application cew on myserver.
Deployment completed on Server myserver

Initiated Task: [10] [Deployer:149026]Redeploy application springglossary on myserver.
Task 10 completed: [Deployer:149026]Redeploy application springglossary on myserver.
Deployment completed on Server myserver

No comments:

Post a Comment