weblogic中两种不同的运行wlst脚本的方式

本文介绍使用 WebLogic Scripting Tool (WLST) 创建单集群域的两种方法。通过 XML 格式的配置指令,演示如何配置管理员服务器、设置 SSL 端口、定义用户密码等关键步骤,并提供了创建和配置集群及托管服务器的示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 第一种方法:
   

<java classname="weblogic.WLST" fork="false" failOnError="true">
    
<classpath refid="wls.classpath" />
    
<arg line="wlst/createCluster.py mydomain" />
</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>

运行上面脚本后,ant输出如下内容,抛出了异常,但是执行的结果的是正确的,也就是说创建的域是正确的,但是在脚本的最后执行exit()方法时,抛出了异常,我想这里的问题应该是fork的问题,在第一个方法中可以自行控制启动的是否是一个独立的进程,而第二种方法不能控制,只能是一个进程,所以在执行exit()方法时,不但退出了wlst脚本的执行,也退出了ant进程。
抛出的异常


wlst.creatCluster:
     [wlst] 
<WLSTTask> Adding test1 to sys.argv
     [wlst] 
<WLSTTask> sys.argv is ['wlst/createCluster.py''test1']
     [wlst] 
<WLSTTask> The script that will be executed
     [wlst] Exiting WebLogic Scripting Tool.

BUILD FAILED
F:work_topfounderworkspacecallcenteruild
-wls.xml:185: Traceback (innermost last):
  File 
"wlstcreateCluster.py", line 127, in ?
  File 
"<iostream>", line 46, in exit
org.eclipse.ant.internal.ui.antsupport.AntSecurityException
    at org.eclipse.ant.internal.ui.antsupport.AntSecurityManager.checkExit(AntSecurityManager.java:
54)
    at java.lang.Runtime.exit(Runtime.java:
88)
    at java.lang.System.exit(System.java:
868)
    at weblogic.management.scripting.WLScriptContext.exit(WLScriptContext.java:
579)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
    at java.lang.reflect.Method.invoke(Method.java:
585)
    at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:
160)
    at org.python.core.PyMethod.__call__(PyMethod.java:
96)
    at org.python.core.PyObject.__call__(PyObject.java:
283)
    at org.python.core.PyObject.invoke(PyObject.java:
2055)
    at org.python.pycode._pyx6.exit$
3(<iostream>:46)
    at org.python.pycode._pyx6.call_function(
<iostream>)
    at org.python.core.PyTableCode.call(PyTableCode.java:
208)
    at org.python.core.PyTableCode.call(PyTableCode.java:
404)
    at org.python.core.PyTableCode.call(PyTableCode.java:
253)
    at org.python.core.PyFunction.__call__(PyFunction.java:
169)
    at org.python.pycode._pyx16.f$
0(wlstcreateCluster.py:127)
    at org.python.pycode._pyx16.call_function(wlstcreateCluster.py)
    at org.python.core.PyTableCode.call(PyTableCode.java:
208)
    at org.python.core.PyCode.call(PyCode.java:
14)
    at org.python.core.Py.runCode(Py.java:
1135)
    at org.python.core.__builtin__.execfile_flags(__builtin__.java:
308)
    at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:
158)
    at weblogic.management.scripting.utils.WLSTInterpreter.execfile(WLSTInterpreter.java:
305)
    at weblogic.ant.taskdefs.management.WLSTTask.execute(WLSTTask.java:
108)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:
275)
    at org.apache.tools.ant.Task.perform(Task.java:
364)
    at org.apache.tools.ant.Target.execute(Target.java:
341)
    at org.apache.tools.ant.Target.performTasks(Target.java:
369)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:
1216)
    at org.apache.tools.ant.Project.executeTarget(Project.java:
1185)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:
40)
    at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:
32)
    at org.apache.tools.ant.Project.executeTargets(Project.java:
1068)
    at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:
423)
    at org.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

 

#=======================================================================================
#
 This is an example of a WLST offline configuration script. This example demonstrates
#
 how to create a single-cluster domain. This sample is based on the Basic WebLogic 
#
 Server Domain template. 
#
#
 Please note that many values used in this script are subject to change based 
#
 on your WebLogic installation and the template you are using.
#
#
 Usage: 
#
      wlst createcluster.py <domain name> 
#
#
=======================================================================================
import string

#=======================================================================================
#
 Open a domain template. 
#
=======================================================================================


template
=wlsHome + '/common/templates/domains/' + domainTemplate

readTemplate(template)

#=======================================================================================
#
 Configure the Administration Server and SSL port.
#
=======================================================================================

cd(
'Servers/AdminServer')
set(
'ListenAddress','')
set(
'ListenPort'7001)

create(
'AdminServer','SSL')
cd(
'SSL/AdminServer')
set(
'Enabled''True')
set(
'ListenPort'7002)

#=======================================================================================
#
 Define the password for user weblogic. You must define the password before you 
#
 can write the domain.
#
=======================================================================================

cd(
'/')
cd(
'Security/base_domain/User/weblogic')
cmo.setPassword(
'weblogic')

#=======================================================================================
#
 Set Options:
#
 - CreateStartMenu:    Enable creation of Start Menu shortcut.
#
 - ServerStartMode:    Set mode to development.
#
 - JavaHome:             Sets home directory for the JVM used when starting the server.
#
 - OverwriteDomain:    Overwrites domain, when saving, if one exists.
#
=======================================================================================

setOption(
'CreateStartMenu''false')
setOption(
'ServerStartMode''dev')
setOption(
'JavaHome',javaHome)
setOption(
'OverwriteDomain''true')

#=======================================================================================
#
 Write the domain and close the domain template.
#
=======================================================================================

writeDomain(beaHome 
+'/user_projects/domains/' + domainName)
closeTemplate()

#=======================================================================================
#
 Reopen the domain.
#
=======================================================================================

readDomain(beaHome 
+'/user_projects/domains/' + domainName)


#=======================================================================================
#
 Create three Managed Servers and configure them.
#
#
 Migratable servers, which provide for both automatic and manual migration 
#
 at the server-level, are created automatically when you create the Managed Servers.
#
=======================================================================================

# 受管服务器的列表,若需要修改修改服务数量,可以修改这个变量,注意不可以重名
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')


#=======================================================================================
#
 Create and configure a cluster and assign the Managed Servers to that cluster.
#
=======================================================================================

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')



#=======================================================================================
#
 Write the domain and close the domain template.
#
=======================================================================================

updateDomain()
closeDomain()

#=======================================================================================
#
 Exit WLST.
#
=======================================================================================

exit()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值