-1
我开始知道weblogic提供了一些使用build.xml部署应用程序的ant任务。无论何时将应用程序部署到我的一个服务器实例中,我都需要为现有域创建一个weblogic用户。 WLserver中是否有任何任务可以实现这一目标?请给我一些建议。代码片段非常可观。使用ant任务的Weblogic部署
谢谢。
我开始知道weblogic提供了一些使用build.xml部署应用程序的ant任务。无论何时将应用程序部署到我的一个服务器实例中,我都需要为现有域创建一个weblogic用户。 WLserver中是否有任何任务可以实现这一目标?请给我一些建议。代码片段非常可观。使用ant任务的Weblogic部署
谢谢。
WLST是为此付出的方式。有关详细信息,请参阅Using the WebLogic Scripting Tool以获取有关从Ant和WLST Command and Variable Reference中调用以获取命令详细信息的详细信息,但下面是用于创建组,用户并将用户添加到组中的示例build.xml和wlst脚本。
的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()