Search This Blog

Monday, August 19, 2013

Invoking WLST from Ant

There are many Middleware Admins who knows do build and deployment out there using Ant to automate their Oracle Fusion Middleware suite configurations on WebLogic domain. and if you would like to embed your WLST configuration scripts into your ant build.xml script files, you can certainly do so. This is simple and easy task which I suppose to post it long back :)

Invoking WLST from a build.xml


Invoking WLST from ANT Script

We can use the WLST script within the build.xml that is between
The other option is you can develop a WLST script in regular fashion, invoke with script path.
We can use both of them part of ANT script(build.xml) invokes part of WLST individual file(.py) then there would be priority which part must be executed first that we can handle with the attribute 'executeScriptBeforeFile' by default it is true you can use false when you don't want.

There are situations where you need to invoke the WLST script from ANT script. There are following possibilities:

  • configure WebLogic resources with ANT
  • Server Control using ANT
  • Monitoring using ANT
The main advantages of using 'WLST with ANT' comes when there is complete templatization of the WebLogic domain configurations for heavy resource configurations as part, such as JMS Resources, JDBC datasources, Message Bridges etc.,

Sample WLSTbuild.xml



  
  
  
    
      
    
  
 
  
    
        
    
   


Sample WLSTbuild.properties file

Now create a properties file say wlstbuild.properties that initialized in the ant script with property element.
weblogic.home.dir=C:/Oracle/Middleware/wlserver_10.3
weblogic.lib.dir=${weblogic.home.dir}/server/lib
wlst.script.source=C:/pbin/test.py

Sample Python script invoked in ant script

The test.py WLST Script will fetch the Server list online WLST.
# Started recording all user actions at Tue Dec 18 22:41:59 IST 2012
svrs = cmo.getServers() 
print 'Servers in the domain are' 
for x in svrs: 
        print x.getName()

How to invoke WLST from ant?

Here the pre-requisite to run the ant script assumed that the WebLogic domain already created and Running fine. Some of the build experts prefer to start internal targets with dashes just to make sure users cannot run them from the command line. In fact, I make it a standard practice to have all internal targets start with - just for this reason. You can try the old double-dash trick. I don't have Ant installed on my current system, so I can't test it. Double dashes is a common Unix trick that most commands use to help end parameters when you have files and stuff that start with a dash. By the way, the tasks should be the last thing on your command line:
$ ant -f wlstbuild.xml -- -stopservers
Targets beginning with a hyphen such as "-stopservers" is valid, and it can be used to name targets that should not be called directly from the command line. Usually, it would be called by someother target such as app-deployment depends on targets as -stopapp, -undeploy, -deploy, -startapp, -stopservers, -startservers etc.

To invoke you need to run the setWLSEnv.sh/cmd
prompt$ ant -f wlstbuild.xml
Running ant embed WLST script

Popular Posts