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

1 comment:

  1. Hello,

    and thank you for this post : I've succeed applying it into my project.

    Basic Weblogic commands work well ; however it failed when I want to call WLST functions shipped into other Fusion Middleware product such as SOA Suite. In this case it seems that WLST launched from Ant is not able to resolve python libraries depencies like the CLI.

    So a command that is OK within the CLI fails with NameError such as this one :

    [wlst] Exception in thread "main" java.lang.IllegalStateException: Traceback (innermost last):
    [wlst] File "/home/s026210/dev/oracleFusionMiddlewareBuild-gen2/scripts/deploy-mediations-functions.py", line 1341, in ?
    [wlst] File "/home/s026210/dev/oracleFusionMiddlewareBuild-gen2/scripts/deploy-mediations-functions.py", line 1197, in mma_exec_cli
    [wlst] File "/home/s026210/dev/oracleFusionMiddlewareBuild-gen2/scripts/deploy-mediations-functions.py", line 1332, in mma_interpretCmd
    [wlst] File "/home/s026210/dev/oracleFusionMiddlewareBuild-gen2/scripts/deploy-mediations-functions.py", line 1131, in mma_importPolicy
    [wlst] NameError: importRepository
    [wlst] at weblogic.management.scripting.WLSTInterpreterInvoker.printError(WLSTInterpreterInvoker.java:110)
    [wlst] at weblogic.management.scripting.WLSTInterpreterInvoker.executePyScript(WLSTInterpreterInvoker.java:103)
    [wlst] at weblogic.management.scripting.WLSTInterpreterInvoker.main(WLSTInterpreterInvoker.java:27)

    when calling the importRepository() function.

    I've tried to reproduce all the work done by the shell scripts (classpath, env variables, JVM args stuffs) but nothing seems to work. WLST still complain about missing function ... and is not able to include python scripts located into $MW_HOME/oracle_common/common/wlst or $MW_HOME/oracle_soa/common/wlst

    Do you have any clue on how realize this with WLST launched from Ant ?

    Thank you,
    --
    Laurent

    ReplyDelete

Please write your comment here

Popular Posts