用于以编程方式部署应用程序的 weblogic 服务器脚本
weblogic server script to deploy application programmatically
我正在寻找通过脚本在 weblogic 服务器上部署应用程序 (EAR/WAR/JAR) 的选项,其中脚本通过 Java main class.
执行
我已经尝试通过 Java 达到同样的效果,例如:
private static final String wlUsername = "'weblogic'";
private static final String wlPassword = "'welcome1'";
private static void connect() {
StringBuffer buffer = new StringBuffer();
buffer.append("connect(");
buffer.append(wlUsername);
buffer.append(",");
buffer.append(wlPassword);
buffer.append(")");
log.debug("connect: "+buffer.toString());
interpreter.exec(buffer.toString());
}
private static void createServers() {
StringBuffer buf = new StringBuffer();
buf.append(startTransaction());
buf.append("man1=create('msEmbedded1','Server')\n");
buf.append("man2=create('msEmbedded2','Server')\n");
buf.append("clus=create('clusterEmbedded','Cluster')\n");
buf.append("man1.setListenPort(8001)\n");
buf.append("man2.setListenPort(9001)\n");
buf.append("man1.setCluster(clus)\n");
buf.append("man2.setCluster(clus)\n");
buf.append(endTransaction());
buf.append("print ‘Script ran successfully ...’ \n");
interpreter.exec(buf.toString());
}
private static String startTransaction() {
StringBuffer buf = new StringBuffer();
buf.append("edit()\n");
buf.append("startEdit()\n");
return buf.toString();
}
private static String endTransaction() {
StringBuffer buf = new StringBuffer();
buf.append("save()\n");
buf.append("activate(block='true')\n");
//buf.append("dumpStack()");
return buf.toString();
}
public static void main(String[] args) {
connect();
enableMbeanServer();
createServers();
}
private static void enableMbeanServer(){
StringBuffer buf = new StringBuffer();
buf.append(startTransaction());
buf.append("set('CompatibilityMBeanServerEnabled', 'true')");
buf.append(endTransaction());
buf.append("shutdown()");
connect();
buf.append("print ‘CompatabilityMBeanServer enabled successfully ...’ \n");
interpreter.exec(buf.toString());
}
但是,最终出现以下异常:
20:41:59.927 DEBUG [main][com.fedex.interfaces.wls.WLSTRunner] connect: connect('weblogic','welcome1')
Connecting to t3://localhost:7001 with userid weblogic ...
The CompatabilityMBeanServer is not initialized properly.
This might happen if the CompatabilityMBeanServer is
disabled via the JMXMBean.
To view the root cause exception use dumpStack()
WLST detected that the RuntimeMBeanServer is not enabled. This
might happen if the RuntimeMBeanServer is disabled via the JMXMBean.
Please ensure that this MBeanServer is enabled. Online WLST cannot
function without this MBeanServer.
Exception in thread "main" Traceback (innermost last):
File "<string>", line 1, in ?
File "<iostream>", line 22, in connect
File "<iostream>", line 648, in raiseWLSTException
WLSTException: Error occured while performing connect : "Cannot connect to WLST."
Use dumpStack() to view the full stacktrace
关于如何从 Java 调用 deploy/undeploy 任务的任何建议或想法?
您可以使用 Weblogic Ant 任务而不是编写应用程序来执行此操作。这也是 Weblogic Ant 任务 docs . You can follow this example。
要重新启动 weblogic,请检查 reference
<target name="start-server">
<wlserver dir="./config" host="127.0.0.1" port="7001" action="start"/>
</target>
如果 WLS 因 RuntimeMBeanServer 未启用而抱怨,只需启用它。
假设:
- WLS 域位于
/oracle/app/oracle/gc_inst/user_projects/domains/GCDomain
- 适用于WLS10.3.6,其他版本未测试
步骤如下:
1) 如果禁用则启用 Platform MBean Server:
1.1。从 WLS 管理控制台,转到 GCDomain > 配置 > 常规 > 高级
1.2。 Select 平台 MBean 服务器已启用,保存更改并激活更改。
1.3。重新启动管理服务器。
2) 为 GCDomain
启用环境变量
cd /oracle/app/oracle/gc_inst/user_projects/domains/GCDomain/bin
source setDomainEnv.sh
3) 从 WLST 启用 RuntimeMBeanServerEnabled
javaweblogic.WLST
Initializing WebLogic Scripting Tool (WLST) ...
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
wls:/offline> readDomain('/oracle/app/oracle/gc_inst/user_projects/domains/GCDomain')
wls:/offline/GCDomain>cd('JMX/NO_NAME_0')
wls:/offline/GCDomain/JMX/NO_NAME_0>set('PlatformMBeanServerUsed','true')
wls:/offline/GCDomain/JMX/NO_NAME_0>set('PlatformMBeanServerEnabled','true')
wls:/offline/GCDomain/JMX/NO_NAME_0>set('RuntimeMBeanServerEnabled', 'true')
wls:/offline/GCDomain/JMX/NO_NAME_0>updateDomain()
wls:/offline/GCDomain/JMX/NO_NAME_0>closeDomain()
wls:/offline>exit()
祝你好运!!
我正在寻找通过脚本在 weblogic 服务器上部署应用程序 (EAR/WAR/JAR) 的选项,其中脚本通过 Java main class.
执行我已经尝试通过 Java 达到同样的效果,例如:
private static final String wlUsername = "'weblogic'";
private static final String wlPassword = "'welcome1'";
private static void connect() {
StringBuffer buffer = new StringBuffer();
buffer.append("connect(");
buffer.append(wlUsername);
buffer.append(",");
buffer.append(wlPassword);
buffer.append(")");
log.debug("connect: "+buffer.toString());
interpreter.exec(buffer.toString());
}
private static void createServers() {
StringBuffer buf = new StringBuffer();
buf.append(startTransaction());
buf.append("man1=create('msEmbedded1','Server')\n");
buf.append("man2=create('msEmbedded2','Server')\n");
buf.append("clus=create('clusterEmbedded','Cluster')\n");
buf.append("man1.setListenPort(8001)\n");
buf.append("man2.setListenPort(9001)\n");
buf.append("man1.setCluster(clus)\n");
buf.append("man2.setCluster(clus)\n");
buf.append(endTransaction());
buf.append("print ‘Script ran successfully ...’ \n");
interpreter.exec(buf.toString());
}
private static String startTransaction() {
StringBuffer buf = new StringBuffer();
buf.append("edit()\n");
buf.append("startEdit()\n");
return buf.toString();
}
private static String endTransaction() {
StringBuffer buf = new StringBuffer();
buf.append("save()\n");
buf.append("activate(block='true')\n");
//buf.append("dumpStack()");
return buf.toString();
}
public static void main(String[] args) {
connect();
enableMbeanServer();
createServers();
}
private static void enableMbeanServer(){
StringBuffer buf = new StringBuffer();
buf.append(startTransaction());
buf.append("set('CompatibilityMBeanServerEnabled', 'true')");
buf.append(endTransaction());
buf.append("shutdown()");
connect();
buf.append("print ‘CompatabilityMBeanServer enabled successfully ...’ \n");
interpreter.exec(buf.toString());
}
但是,最终出现以下异常:
20:41:59.927 DEBUG [main][com.fedex.interfaces.wls.WLSTRunner] connect: connect('weblogic','welcome1')
Connecting to t3://localhost:7001 with userid weblogic ...
The CompatabilityMBeanServer is not initialized properly.
This might happen if the CompatabilityMBeanServer is
disabled via the JMXMBean.
To view the root cause exception use dumpStack()
WLST detected that the RuntimeMBeanServer is not enabled. This
might happen if the RuntimeMBeanServer is disabled via the JMXMBean.
Please ensure that this MBeanServer is enabled. Online WLST cannot
function without this MBeanServer.
Exception in thread "main" Traceback (innermost last):
File "<string>", line 1, in ?
File "<iostream>", line 22, in connect
File "<iostream>", line 648, in raiseWLSTException
WLSTException: Error occured while performing connect : "Cannot connect to WLST."
Use dumpStack() to view the full stacktrace
关于如何从 Java 调用 deploy/undeploy 任务的任何建议或想法?
您可以使用 Weblogic Ant 任务而不是编写应用程序来执行此操作。这也是 Weblogic Ant 任务 docs . You can follow this example。
要重新启动 weblogic,请检查 reference
<target name="start-server">
<wlserver dir="./config" host="127.0.0.1" port="7001" action="start"/>
</target>
如果 WLS 因 RuntimeMBeanServer 未启用而抱怨,只需启用它。
假设:
- WLS 域位于 /oracle/app/oracle/gc_inst/user_projects/domains/GCDomain
- 适用于WLS10.3.6,其他版本未测试
步骤如下:
1) 如果禁用则启用 Platform MBean Server:
1.1。从 WLS 管理控制台,转到 GCDomain > 配置 > 常规 > 高级
1.2。 Select 平台 MBean 服务器已启用,保存更改并激活更改。
1.3。重新启动管理服务器。
2) 为 GCDomain
启用环境变量cd /oracle/app/oracle/gc_inst/user_projects/domains/GCDomain/bin
source setDomainEnv.sh
3) 从 WLST 启用 RuntimeMBeanServerEnabled javaweblogic.WLST
Initializing WebLogic Scripting Tool (WLST) ...
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
wls:/offline> readDomain('/oracle/app/oracle/gc_inst/user_projects/domains/GCDomain')
wls:/offline/GCDomain>cd('JMX/NO_NAME_0')
wls:/offline/GCDomain/JMX/NO_NAME_0>set('PlatformMBeanServerUsed','true')
wls:/offline/GCDomain/JMX/NO_NAME_0>set('PlatformMBeanServerEnabled','true')
wls:/offline/GCDomain/JMX/NO_NAME_0>set('RuntimeMBeanServerEnabled', 'true')
wls:/offline/GCDomain/JMX/NO_NAME_0>updateDomain()
wls:/offline/GCDomain/JMX/NO_NAME_0>closeDomain()
wls:/offline>exit()
祝你好运!!