第一种方法:
<
java
classname
="weblogic.WLST"
fork
="false"
failOnError
="true"
>
< classpath refid ="wls.classpath" />
< arg line ="wlst/createCluster.pymydomain" />
</ java >
< classpath refid ="wls.classpath" />
< arg line ="wlst/createCluster.pymydomain" />
</ java >
成功执行
第二种方法
<
taskdef
name
="wlst"
classname ="weblogic.ant.taskdefs.management.WLSTTask"
classpathref ="wls.classpath" />
< wlst fileName ="wlst/createCluster.py"
arguments ="mydomain"
debug ="true"
failOnError ="true" >
</ wlst >
classname ="weblogic.ant.taskdefs.management.WLSTTask"
classpathref ="wls.classpath" />
< wlst fileName ="wlst/createCluster.py"
arguments ="mydomain"
debug ="true"
failOnError ="true" >
</ wlst >
运行上面脚本后,ant输出如下内容,抛出了异常,但是执行的结果的是正确的,也就是说创建的域是正确的,但是在脚本的最后执行exit()方法时,抛出了异常,我想这里的问题应该是fork的问题,在第一个方法中可以自行控制启动的是否是一个独立的进程,而第二种方法不能控制,只能是一个进程,所以在执行exit()方法时,不但退出了wlst脚本的执行,也退出了ant进程。
抛出的异常
wlst.creatCluster:
[wlst] < WLSTTask > Addingtest1tosys.argv
[wlst] < WLSTTask > sys.argvis[ ' wlst/createCluster.py ' , ' test1 ' ]
[wlst] < WLSTTask > Thescriptthatwillbeexecuted
[wlst]ExitingWebLogicScriptingTool.
BUILDFAILED
F:work_topfounderworkspacecallcenteruild - wls.xml: 185 :Traceback(innermostlast):
File " wlstcreateCluster.py " ,line 127 ,in ?
File " <iostream> " ,line 46 ,inexit
org.eclipse.ant.internal.ui.antsupport.AntSecurityException
atorg.eclipse.ant.internal.ui.antsupport.AntSecurityManager.checkExit(AntSecurityManager.java: 54 )
atjava.lang.Runtime.exit(Runtime.java: 88 )
atjava.lang.System.exit(System.java: 868 )
atweblogic.management.scripting.WLScriptContext.exit(WLScriptContext.java: 579 )
atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)
atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: 39 )
atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java: 25 )
atjava.lang.reflect.Method.invoke(Method.java: 585 )
atorg.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java: 160 )
atorg.python.core.PyMethod.__call__(PyMethod.java: 96 )
atorg.python.core.PyObject.__call__(PyObject.java: 283 )
atorg.python.core.PyObject.invoke(PyObject.java: 2055 )
atorg.python.pycode._pyx6.exit$ 3 ( < iostream > : 46 )
atorg.python.pycode._pyx6.call_function( < iostream > )
atorg.python.core.PyTableCode.call(PyTableCode.java: 208 )
atorg.python.core.PyTableCode.call(PyTableCode.java: 404 )
atorg.python.core.PyTableCode.call(PyTableCode.java: 253 )
atorg.python.core.PyFunction.__call__(PyFunction.java: 169 )
atorg.python.pycode._pyx16.f$ 0 (wlstcreateCluster.py: 127 )
atorg.python.pycode._pyx16.call_function(wlstcreateCluster.py)
atorg.python.core.PyTableCode.call(PyTableCode.java: 208 )
atorg.python.core.PyCode.call(PyCode.java: 14 )
atorg.python.core.Py.runCode(Py.java: 1135 )
atorg.python.core.__builtin__.execfile_flags(__builtin__.java: 308 )
atorg.python.util.PythonInterpreter.execfile(PythonInterpreter.java: 158 )
atweblogic.management.scripting.utils.WLSTInterpreter.execfile(WLSTInterpreter.java: 305 )
atweblogic.ant.taskdefs.management.WLSTTask.execute(WLSTTask.java: 108 )
atorg.apache.tools.ant.UnknownElement.execute(UnknownElement.java: 275 )
atorg.apache.tools.ant.Task.perform(Task.java: 364 )
atorg.apache.tools.ant.Target.execute(Target.java: 341 )
atorg.apache.tools.ant.Target.performTasks(Target.java: 369 )
atorg.apache.tools.ant.Project.executeSortedTargets(Project.java: 1216 )
atorg.apache.tools.ant.Project.executeTarget(Project.java: 1185 )
atorg.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java: 40 )
atorg.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java: 32 )
atorg.apache.tools.ant.Project.executeTargets(Project.java: 1068 )
atorg.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java: 423 )
atorg.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java: 137 )
org.eclipse.ant.internal.ui.antsupport.AntSecurityException:org.eclipse.ant.internal.ui.antsupport.AntSecurityException
createCluster.py
#
=======================================================================================
# ThisisanexampleofaWLSTofflineconfigurationscript.Thisexampledemonstrates
# howtocreateasingle-clusterdomain.ThissampleisbasedontheBasicWebLogic
# ServerDomaintemplate.
#
# Pleasenotethatmanyvaluesusedinthisscriptaresubjecttochangebased
# onyourWebLogicinstallationandthetemplateyouareusing.
#
# Usage:
# wlstcreatecluster.py<domainname>
#
# =======================================================================================
import string
# =======================================================================================
# Openadomaintemplate.
# =======================================================================================
template = wlsHome + ' /common/templates/domains/ ' + domainTemplate
readTemplate(template)
# =======================================================================================
# ConfiguretheAdministrationServerandSSLport.
# =======================================================================================
cd( ' Servers/AdminServer ' )
set( ' ListenAddress ' , '' )
set( ' ListenPort ' , 7001 )
create( ' AdminServer ' , ' SSL ' )
cd( ' SSL/AdminServer ' )
set( ' Enabled ' , ' True ' )
set( ' ListenPort ' , 7002 )
# =======================================================================================
# Definethepasswordforuserweblogic.Youmustdefinethepasswordbeforeyou
# canwritethedomain.
# =======================================================================================
cd( ' / ' )
cd( ' Security/base_domain/User/weblogic ' )
cmo.setPassword( ' weblogic ' )
# =======================================================================================
# SetOptions:
# -CreateStartMenu:EnablecreationofStartMenushortcut.
# -ServerStartMode:Setmodetodevelopment.
# -JavaHome:SetshomedirectoryfortheJVMusedwhenstartingtheserver.
# -OverwriteDomain:Overwritesdomain,whensaving,ifoneexists.
# =======================================================================================
setOption( ' CreateStartMenu ' , ' false ' )
setOption( ' ServerStartMode ' , ' dev ' )
setOption( ' JavaHome ' ,javaHome)
setOption( ' OverwriteDomain ' , ' true ' )
# =======================================================================================
# Writethedomainandclosethedomaintemplate.
# =======================================================================================
writeDomain(beaHome + ' /user_projects/domains/ ' + domainName)
closeTemplate()
# =======================================================================================
# Reopenthedomain.
# =======================================================================================
readDomain(beaHome + ' /user_projects/domains/ ' + domainName)
# =======================================================================================
# CreatethreeManagedServersandconfigurethem.
#
# Migratableservers,whichprovideforbothautomaticandmanualmigration
# attheserver-level,arecreatedautomaticallywhenyoucreatetheManagedServers.
# =======================================================================================
# 受管服务器的列表,若需要修改修改服务数量,可以修改这个变量,注意不可以重名
mServers = ' ms1 ' , ' ms2 ' , ' ms3 '
startPort = 8001
for mServer in mServers:
cd( ' / ' )
create(mServer, ' Server ' )
cd( ' Server/ ' + mServer)
set( ' ListenPort ' ,startPort)
startPort += 10
set( ' ListenAddress ' , ' localhost ' )
# =======================================================================================
# CreateandconfigureaclusterandassigntheManagedServerstothatcluster.
# =======================================================================================
clusterName = ' wlsCluster '
cd( ' / ' )
create(clusterName, ' Cluster ' )
assign( ' Server ' ,string.join(mServers, ' , ' ), ' Cluster ' ,clusterName)
cd( ' Clusters/ ' + clusterName)
set( ' MulticastAddress ' , ' 237.0.0.101 ' )
set( ' MulticastPort ' , 9200 )
set( ' WeblogicPluginEnabled ' , ' true ' )
# =======================================================================================
# Writethedomainandclosethedomaintemplate.
# =======================================================================================
updateDomain()
closeDomain()
# =======================================================================================
# ExitWLST.
# =======================================================================================
exit()
# ThisisanexampleofaWLSTofflineconfigurationscript.Thisexampledemonstrates
# howtocreateasingle-clusterdomain.ThissampleisbasedontheBasicWebLogic
# ServerDomaintemplate.
#
# Pleasenotethatmanyvaluesusedinthisscriptaresubjecttochangebased
# onyourWebLogicinstallationandthetemplateyouareusing.
#
# Usage:
# wlstcreatecluster.py<domainname>
#
# =======================================================================================
import string
# =======================================================================================
# Openadomaintemplate.
# =======================================================================================
template = wlsHome + ' /common/templates/domains/ ' + domainTemplate
readTemplate(template)
# =======================================================================================
# ConfiguretheAdministrationServerandSSLport.
# =======================================================================================
cd( ' Servers/AdminServer ' )
set( ' ListenAddress ' , '' )
set( ' ListenPort ' , 7001 )
create( ' AdminServer ' , ' SSL ' )
cd( ' SSL/AdminServer ' )
set( ' Enabled ' , ' True ' )
set( ' ListenPort ' , 7002 )
# =======================================================================================
# Definethepasswordforuserweblogic.Youmustdefinethepasswordbeforeyou
# canwritethedomain.
# =======================================================================================
cd( ' / ' )
cd( ' Security/base_domain/User/weblogic ' )
cmo.setPassword( ' weblogic ' )
# =======================================================================================
# SetOptions:
# -CreateStartMenu:EnablecreationofStartMenushortcut.
# -ServerStartMode:Setmodetodevelopment.
# -JavaHome:SetshomedirectoryfortheJVMusedwhenstartingtheserver.
# -OverwriteDomain:Overwritesdomain,whensaving,ifoneexists.
# =======================================================================================
setOption( ' CreateStartMenu ' , ' false ' )
setOption( ' ServerStartMode ' , ' dev ' )
setOption( ' JavaHome ' ,javaHome)
setOption( ' OverwriteDomain ' , ' true ' )
# =======================================================================================
# Writethedomainandclosethedomaintemplate.
# =======================================================================================
writeDomain(beaHome + ' /user_projects/domains/ ' + domainName)
closeTemplate()
# =======================================================================================
# Reopenthedomain.
# =======================================================================================
readDomain(beaHome + ' /user_projects/domains/ ' + domainName)
# =======================================================================================
# CreatethreeManagedServersandconfigurethem.
#
# Migratableservers,whichprovideforbothautomaticandmanualmigration
# attheserver-level,arecreatedautomaticallywhenyoucreatetheManagedServers.
# =======================================================================================
# 受管服务器的列表,若需要修改修改服务数量,可以修改这个变量,注意不可以重名
mServers = ' ms1 ' , ' ms2 ' , ' ms3 '
startPort = 8001
for mServer in mServers:
cd( ' / ' )
create(mServer, ' Server ' )
cd( ' Server/ ' + mServer)
set( ' ListenPort ' ,startPort)
startPort += 10
set( ' ListenAddress ' , ' localhost ' )
# =======================================================================================
# CreateandconfigureaclusterandassigntheManagedServerstothatcluster.
# =======================================================================================
clusterName = ' wlsCluster '
cd( ' / ' )
create(clusterName, ' Cluster ' )
assign( ' Server ' ,string.join(mServers, ' , ' ), ' Cluster ' ,clusterName)
cd( ' Clusters/ ' + clusterName)
set( ' MulticastAddress ' , ' 237.0.0.101 ' )
set( ' MulticastPort ' , 9200 )
set( ' WeblogicPluginEnabled ' , ' true ' )
# =======================================================================================
# Writethedomainandclosethedomaintemplate.
# =======================================================================================
updateDomain()
closeDomain()
# =======================================================================================
# ExitWLST.
# =======================================================================================
exit()