Ant build pointing Weblogic to a domain

I am trying to create a build file that will get weblogic server to point to a domain and then start the weblogic server.  So basically I want to build the app, deploy it and get weblogic server to point to a domain.
imramaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
BeckyConnect With a Mentor Commented:
You'd need to write a python script and pass that to your ant build file.  Something like this:

<exec executable="${weblogic_server_home}/common/bin/wlst.cmd"
     dir="${weblogic_domain_home}" failonerror="true" vmlauncher="false">
            <arg value="${weblogic_domain_home}add_server_to_domain.py"/>
            <arg value="${weblogic_domain_template}"/>
            <arg value="${weblogic_domain_name}.properties" />
</exec>

Weblogic has examples of how to do a number of things using python to configure a domain.  Here's an example:

#Description: Configures a domain from a properties file
#Usage: /app/bea/weblogic92/common/bin/wlst.sh ./wl10_configure_domain.py config
from java.io import File
from java.io import FileInputStream
from java.util import Properties
from java.lang import String
import re
import os
import sys
import glob
import string
import wl10_shared_functions
from wl10_shared_functions import *

try:
  redirect('./wlst.log', 'true')

  #############################################################################
  ####   Load properties
  #############################################################################
  envConfigPropFile = sys.argv[1]
  deployapps = sys.argv[2]
  print "Loading Propery file " + envConfigPropFile + "..."
  PROPS = loadProps(envConfigPropFile)
  sysUser = PROPS["weblogic_system_user"]
  sysPwd = PROPS["weblogic_system_password"]
  domainName = PROPS["weblogic_domain_name"]
  adminServerName = PROPS["weblogic_admin_server_name"]
  adminSnmpPort = PROPS["weblogic_admin_snmp_port"]
  adminSnmpName = PROPS["weblogic_admin_snmp_name"]
  configVersion = PROPS["weblogic_config_version"]
  prodMode = PROPS["weblogic_production_mode_enabled"]
  maxPostSize = PROPS["weblogic_max_post_size"]
  logDir = PROPS["logDir"]
  adminPort = PROPS["weblogic_admin_port"]
  portEnabled = PROPS["weblogic_admin_port_enabled"]
  sslPort = PROPS["weblogic_admin_ssl_port"]
  sslEnabled = PROPS["weblogic_admin_ssl_enabled"]
  adminUrl = "t3://localhost:" + adminPort
  if portEnabled == "false" and sslEnabled == "true":
    adminUrl = "t3s://localhost:" + sslPort

  #############################################################################
  ####   Connect to Admin Server
  #############################################################################
  connectToServer(sysUser, sysPwd, adminUrl)
  transactionStart()

  #############################################################################
  ####   Admin Server Configuration
  #############################################################################
  setupAdminServer(adminServerName, adminPort, portEnabled,
                   sslPort, sslEnabled, maxPostSize)

  print "Checkpoint commit..."
  transactionCommit()
  transactionStart()

  #############################################################################
  ####   Security Configuration
  #############################################################################
  setupSecurityProperties(domainName, "c2s275", aProperties={"WebAppFilesCaseInsensitive": "os", "NodeManagerUsername": sysUser,
                                                             "EnforceStrictURLPattern": "false", "CompatibilityConnectionFiltersEnabled": "true",
                                                             "AnonymousAdminLookupEnabled": "true", "Credential": sysPwd})

  transactionCommit()
  transactionStart()

  setupAuthenticatorProvider("DefaultAuthenticator", domainName, "myrealm", "weblogic.security.providers.authentication.DefaultAuthenticator",
                             aProperties={"ControlFlag": "SUFFICIENT"}
                            )

  setupAuthenticatorProvider("CorpActiveDirectoryAuthenticator",
                             domainName, "myrealm",
     "weblogic.security.providers.authentication.ActiveDirectoryAuthenticator",
                             aProperties={"GroupBaseDN": PROPS["adCorpGroupBaseDN"].replace('"',' ').strip(),
                                          "CacheTTL": "48",
                                          "FollowReferrals": "false",
                                          "Host": PROPS["adCorpServerHost"].replace('"',' ').strip(),
                                          "ControlFlag": "SUFFICIENT",
                                          "UserFromNameFilter": "(&(cn=%u)(objectclass=user))",
                                          "UserBaseDN": PROPS["adCorpUserBaseDN"].replace('"',' ').strip(),
                                          "Principal": PROPS["adCorpPrincipal"].replace('"',' ').strip(),
                                          "Credential": PROPS["adCorpServerCredential"]
                                         }
                            )

  setupAuthenticatorProvider("ExtActiveDirectoryAuthenticator",
                             domainName, "myrealm",
     "weblogic.security.providers.authentication.ActiveDirectoryAuthenticator",
                             aProperties={"GroupBaseDN": PROPS["adExtGroupBaseDN"].replace('"',' ').strip(),
                                          "CacheTTL": "48",
                                          "FollowReferrals": "false",
                                          "Host": PROPS["adExtServerHost"].replace('"',' ').strip(),
                                          "ControlFlag": "SUFFICIENT",
                                          "UserFromNameFilter": "(&(cn=%u)(objectclass=user))",
                                          "UserBaseDN": PROPS["adExtUserBaseDN"].replace('"',' ').strip(),
                                          "Principal": PROPS["adExtPrincipal"].replace('"',' ').strip(),
                                          "Credential": PROPS["adExtServerCredential"]
                                          }
                            )

  setupAuthenticatorProvider(PROPS["identityAsserter_name"], domainName, "myrealm", PROPS["identityAsserter_className"],
                            aProperties={"ActiveTypes": jarray.array([PROPS["identityAsserter_activeTypes"]], String)
                                        }
                            )

  transactionCommit()
  transactionStart()

  #############################################################################
  ####   Mail Session and Logging Configuration
  #############################################################################
  setupMailSession(adminServerName, "MailSession", "MailSession", PROPS["weblogic_mail_properties"])

  setupServerLog(adminServerName, logDir+"/debug/"+adminServerName+".log", { "RotationType":"byTime", "LogFileSeverity": "Debug", "StdoutSeverity": "Warning" })

  setupDomainLog(domainName, logDir+"/debug/"+domainName+".log", {'RotationType': 'byTime' })

  setupWebLog(adminServerName, logDir+"/access/"+adminServerName+"_access.log", { "NumberOfFilesLimited": "false", "LogFileFormat": "common", "RotationType": "byTime", "FileCount": "1", "FileMinSize": "65535" } )

  transactionCommit()


  #############################################################################
  ### Create Users and Groups
  #############################################################################
  wl.serverConfig()
  print "Creating User"
  createUser(domainName, "ldapservices_hnweb_client", PROPS["ldapservices_hnweb_client_Password"], "ldap client user")

  print "Creating Groups"
  createGroup(domainName, "weblogic.ldapservices.public_user_clients","weblogic.ldapservices.public_user_clients")
  createGroup(domainName, "weblogic.ldapservices.user_clients","weblogic.ldapservices.user_clients")
  createGroup(domainName, "weblogic.ldapservices.administrator_clients","weblogic.ldapservices.administrator_clients")

  print "Adding members to grops"
  addMemberToGroup(domainName, "weblogic.ldapservices.public_user_clients","ldapservices_hnweb_client")
  addMemberToGroup(domainName, "weblogic.ldapservices.user_clients","ldapservices_hnweb_client")
  addMemberToGroup(domainName, "weblogic.ldapservices.administrator_clients","ldapservices_hnweb_client")


  if PROPS["weblogic_cluster_name"] == None:
    print "weblogic_cluster_name is null, skipping creation of cluster and managed hosts"

    #############################################################################
    ####   JMS Configuration for the admin server
    #############################################################################
    fStore = PROPS["weblogic_admin_file_store"]
    jmsServer = PROPS["weblogic_admin_jms_server"]
    jmsModule = PROPS["weblogic_admin_jms_module"]

    transactionStart()

    print "Setting up JMS Resources fileStore=" + fStore + ", jmsServer=" + jmsServer + ", jmsModule=" + jmsModule
    setupFileStore(fStore, adminServerName, fStore, "Direct-Write")
    setupJMSServer(jmsServer, fStore, adminServerName, aAllowsPersistentDowngrade="false", aHostingTemporaryDestinations="true")
    setupJMSModule(adminServerName, jmsModule)
    setupJMSSubDeployment(jmsServer, jmsModule)
    print "Checkpoint commit..."

    transactionCommit()

  else:
    transactionStart()

    #############################################################################
    ####   Cluster configuration
    #############################################################################
    clusterName = PROPS["weblogic_cluster_name"]
    clusterAddr = PROPS["weblogic_cluster_address"]
    multicastAddr = PROPS["weblogic_multicast_address"]
    multicastPort = PROPS["weblogic_multicast_port"]
    setupCluster(clusterName, clusterAddr, multicastAddr, multicastPort)

    #############################################################################
    ####   Managed Server configuration
    #############################################################################
    managedHosts = PROPS["weblogic_managed_hosts"].replace('"',' ').strip()
    if managedHosts != None:
      mHosts = managedHosts.split(' ')
      for mHost in mHosts:
        hostserver = mHost.split(':')
        mHost = hostserver[0]
        mName = hostserver[1]
        mPort = hostserver[2]
        mSslPort = hostserver[3]
        fileStore = hostserver[6]
        jmsServerName = hostserver[7]
        setupManagedServer(mName, mPort, clusterName, 'true', mSslPort, maxPostSize)
        setupServerLog(mName, logDir+"/debug/"+mName+".log", { "RotationType":"byTime", "LogFileSeverity": "Debug", "StdoutSeverity": "Warning" })
        setupWebLog(mName, logDir+"/access/"+mName+"_access.log", { "NumberOfFilesLimited": "false", "LogFileFormat": "common", "RotationType": "byTime", "FileCount": "1", "FileMinSize": "65535" } )
        setupFileStore(fileStore, mName, fileStore, "Direct-Write")
        setupJMSServer(jmsServerName, fileStore, mName, aAllowsPersistentDowngrade="false", aHostingTemporaryDestinations="true")

    print "Checkpoint commit..."
    transactionCommit()

except:
  print "Unexpected error: ", sys.exc_info()[0]
  dumpStack()
  raise





Then in ant you deploy to the server:

<macrodef name="weblogicDeploy">
        <attribute name="actionToTake"/>
        <attribute name="whatToDeploy"/>
        <sequential>
            <property name="wls.userconfigfile" value="resources/config/deploy/${env}.userConfig"/>
            <property name="wls.userkeyfile" value="resources/config/deploy/${env}.userKey"/>
            <taskdef name="wldeploy" onerror="fail" classname="weblogic.ant.taskdefs.management.WLDeploy" classpathref="wls.ant.classpath"/>
            <wldeploy action="@{actionToTake}"
                                  name="${application.name}"
                                  source="@{whatToDeploy}"
                                  upload="false"
                                  failonerror="true"
                                  remote="${wls.remote}"
                                  adminurl="t3://${wls.hostname}:${wls.port}"
                                  targets="${wls.server.name}"
                                  userconfigfile="${wls.userconfigfile}"
                                  userkeyfile="${wls.userkeyfile}" />
        </sequential>
    </macrodef>
0
All Courses

From novice to tech pro — start learning today.