以编程方式部署应用程序的 weblogic 服务器脚本 [英] weblogic server script to deploy application programmatically

查看:129
本文介绍了以编程方式部署应用程序的 weblogic 服务器脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找通过脚本在 weblogic 服务器上部署应用程序(EAR/WAR/JAR)的选项,其中脚本通过 Java 主类执行.

我尝试通过 Java 实现相同的目标,例如:

private static final String wlUsername = "'weblogic'";私有静态最终字符串 wlPassword = "'welcome1'";私有静态无效连接(){StringBuffer 缓冲区 = new StringBuffer();buffer.append("connect(");buffer.append(wlUsername);buffer.append(",");buffer.append(wlPassword);buffer.append(")");log.debug("connect:"+buffer.toString());解释器.exec(buffer.toString());}私有静态无效 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 ‘脚本运行成功...’ \n");解释器.exec(buf.toString());}私有静态字符串 startTransaction() {StringBuffer buf = new StringBuffer();buf.append("edit()\n");buf.append("startEdit()\n");返回 buf.toString();}私有静态字符串 endTransaction() {StringBuffer buf = new StringBuffer();buf.append("save()\n");buf.append("activate(block='true')\n");//buf.append("dumpStack()");返回 buf.toString();}公共静态无效主(字符串 [] args){连接();enableMbeanServer();创建服务器();}私有静态无效 enableMbeanServer(){StringBuffer buf = new StringBuffer();buf.append(startTransaction());buf.append("set('CompatibilityMBeanServerEnabled', 'true')");buf.append(endTransaction());buf.append("关机()");连接();buf.append("打印'CompatabilityMBeanServer 启用成功......'\n");解释器.exec(buf.toString());}

但是,最终出现以下异常:

20:41:59.927 DEBUG [main][com.fedex.interfaces.wls.WLSTRunner] connect: connect('weblogic','welcome1')使用用户 ID weblogic 连接到 t3://localhost:7001 ...CompatabilityMBeanServer 未正确初始化.如果 CompatabilityMBeanServer 是通过 JMXMBean 禁用.要查看根本原因异常,请使用 dumpStack()WLST 检测到 RuntimeMBeanServer 未启用.这如果通过 JMXMBean 禁用了 RuntimeMBeanServer,则可能会发生这种情况.请确保启用此 MBeanServer.在线 WLST 不能没有这个 MBeanServer 的函数.线程main"回溯中的异常(最里面的最后一个):文件",第 1 行,在 ?文件",第 22 行,在连接中文件",第 648 行,在 raiseWLSTException 中WLSTException:执行连接时出错:无法连接到 WLST."使用 dumpStack() 查看完整的堆栈跟踪

对如何从 Java 调用部署/取消部署任务有任何建议或想法吗?

解决方案

您可以使用 Weblogic Ant 任务而不是编写应用程序来完成该任务.这是 Weblogic Ant 任务 docs.您也可以按照此示例进行操作.

要重新启动 weblogic,请查看参考

<wlserver dir="./config" host="127.0.0.1" port="7001" action="start"/></目标>

这篇文章

Am looking for an option to deploy application(EAR/WAR/JAR) on weblogic server through script, where the script is executed through Java main class.

I have tried to achieve the same through Java like:

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());
}

But, end up with the below exception:

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

Any suggestion or any idea how to invoke deploy/undeploy task from Java?

解决方案

You can use Weblogic Ant task instead of writing an application to do that. This is Weblogic Ant Task docs . You can follow this example as well.

To restart weblogic, check the reference

<target name="start-server">
  <wlserver dir="./config" host="127.0.0.1" port="7001" action="start"/>
</target>

and this post

这篇关于以编程方式部署应用程序的 weblogic 服务器脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆