Tuesday, December 22, 2009

Weblogic Server : Quick EAR Deployment using WLST

" The WebLogic Scripting Tool (WLST) is a command-line scripting environment that you can use to create, manage, and monitor WebLogic Server domains. "


You can use WLST to quickly deploy an Application EAR File in a Weblogic Server.

What do you need ?
  • the EAR file ( uploaded to a directory in the target WebLogic Server )
  • A simple WLST script
  • Credentials for the Weblogic Server ( preferrably, the weblogic user ).
How do we do it ?
  • Upload your EAR file to a directory in the target Weblogic Server
/app/home/myUser/
  • Write a simple WLST Script to do your work and save it as "myApp.py"

print '*** WEBLOGIC : START ***'

print 'connecting to admin server....'
connect( 'weblogic', 'weblogic', 't3://localhost:8001', adminServerName='AdminServer' )

print 'stopping and undeploying ....'

stopApplication('myApplication')
undeploy('myApplication')

print 'deploying....'

deploy('myApplication', '/app/home/myUser/myApplication.ear', targets='AdminServer')
startApplication('FoundationSearch')

print 'disconnecting from admin server....'
disconnect()
exit()

print '*** WEBLOGIC : STOP ***'
  • Open a Terminal Window / Command Prompt
  • Run the setDomainEnv.sh ( or setDomainEnv.bat ) script to set the required environment variables.
  • Switch to the /common/bin directory of your Weblogic Server
  • run the wlst.sh / wlst.bat script to open the Scripting Environment.
  • Execute your WLST Script :-
execfile('myApp.py')


That's it ! You can now stop an application, undeloy it, deploy it & start an application with a simple script !

You need to watch out for two small things :-

  • The WAR File and some of the classes / libs are "cached" under the /tmp/_WL_user/myApplication/ folder. You may need to delete them before you execute your script.
  • Make sure the EAR file is available in a folder in the same node as the Server.

No comments: