Search code examples
pythonweblogicearwlst

Determine if EAR Has Been Deployed in WebLogic Server Using WLST?


I am trying to create a simple python script that deploys my EAR file to the AdminServer of Weblogic. I have searched the internet and the documentation provided by Oracle, but I cannot find a way to determine if the application has been previously deployed. I would like my script to check if it has been, and if so, issue a redeploy command. If not, issue a deploy command.

I have tried to modify example scripts I've found, and although they've worked, they are not behaving as intended. One of the things I was trying to do was check (using the cd command) if my EAR was in the deployments folder of WebLogic and if it was, issue the redeploy. If not, it should throw an Exception, where I would issue the deploy. However, an Exception is thrown everytime when I issue the cd command in my script:

try:
    print 'Checking for the existence of the ' + applicationName + ' application.....'
    cd('C:\\Oracle\\Middleware\\user_projects\\domains\\base_domain\\config\\deployments\\MyTestEAR.ear\\')
    print 'Redeploying....'
    #Commands to redeploy....

except WLSTException:
    #Commands to deploy

I'm running this script on Windows using execfile("C:\MyTestDeployer.py") command after setting my environment variables using the WLST Scripting Tool. Any ideas? I've also tried to use a different path in my cd command, but to no avail. Any ideas?


Solution

  • It works for me:

    print 'stopping and undeploying ...'
    
    try:
        stopApplication('WebApplication')
        undeploy('WebApplication')
        print 'Redeploying...'
    
    except Exception:
        print 'Deploy...'
    
    deploy('WebApplication', '/home/saeed/project/test/WebApplication/dist/WebApplication.war')
    startApplication('WebApplication2')