使用ant任务进行Weblogic部署

时间:2015-02-12 07:53:16

标签: ant weblogic wlst

我发现weblogic提供了一些使用build.xml部署应用程序的ant任务。每当我将应用程序部署到我的一个服务器实例中时,我需要为现有域创建一个weblogic用户。 WLserver是否有任何可用的任务来实现这一目标?请给我一些建议。 代码片段非常值得注意。

感谢。

1 个答案:

答案 0 :(得分:2)

WLST是实现这一目标的方法。有关从Ant和Using the WebLogic Scripting Tool调用此命令的详细信息,请参阅WLST Command and Variable Reference,但下面是一个示例build.xml和wlst脚本,用于创建组,用户并将用户添加到组中。 / p>

的build.xml

<?xml version="1.0" encoding="windows-1252" ?>
<project default="create_user">

  <property environment="env"/>

  <path id="wl.classpath">
    <pathelement location="${env.ORACLE_HOME}/patch_wls1036/profiles/default/sys_manifest_classpath/weblogic_patch.jar"/>
    <pathelement location="${env.ORACLE_HOME}/patch_ocp371/profiles/default/sys_manifest_classpath/weblogic_patch.jar"/>
    <pathelement location="${env.JAVA_HOME}/lib/tools.jar"/>
    <pathelement location="${env.ORACLE_HOME}/wlserver_10.3/server/lib/weblogic_sp.jar"/>
    <pathelement location="${env.ORACLE_HOME}/wlserver_10.3/server/lib/weblogic.jar"/>
    <pathelement location="${env.ORACLE_HOME}/modules/features/weblogic.server.modules_10.3.6.0.jar"/>
    <pathelement location="${env.ORACLE_HOME}/wlserver_10.3/server/lib/webservices.jar"/>
    <pathelement location="${env.ORACLE_HOME}/modules/org.apache.ant_1.7.1/lib/ant-all.jar"/>
    <pathelement location="${env.ORACLE_HOME}/modules/net.sf.antcontrib_1.1.0.0_1-0b2/lib/ant-contrib.jar"/>
    <fileset dir="${env.ORACLE_HOME}/oracle_common/common/wlst/lib">
      <include name="*.jar"/>
    </fileset>
    <fileset dir="${env.ORACLE_HOME}/oracle_common/common/wlst/resources">
      <include name="*.jar"/>
    </fileset>
    <pathelement location="${env.ORACLE_HOME}/utils/config/10.3/config-launch.jar"/>
  </path>

  <target name="create_user">

    <taskdef name="wlst"
        classname="weblogic.ant.taskdefs.management.WLSTTask" classpathref="wl.classpath" />

    <wlst debug="true" failonerror="true" executeScriptBeforeFile="true" fileName="create_user.py">
      <classpath>
        <path refid="wl.classpath"/>
      </classpath>
    </wlst> 
  </target>    

</project>

create_user.py

from weblogic.management.utils import AlreadyExistsException

connect('weblogic', 'password', 't3://localhost:7001')
serverConfig()
authenticator = cmo.getSecurityConfiguration().getDefaultRealm().lookupAuthenticationProvider('DefaultAuthenticator')

try:
    print("Creating group.")
    authenticator.createGroup('groupName', 'groupDescription')
    print("Group created.")
except AlreadyExistsException:
    print("Ignoring group as it already exists.")
    pass

print("Creating user 'groupName'.")    
authenticator.createUser('userName', 'userPassword%!1', 'userDescription')

print("Addding user to group.")
authenticator.addMemberToGroup('groupName', 'userName') 

disconnect()
相关问题