获取部署在 weblogic 服务器上的所有应用程序的列表 [英] Get list of all applications deployed on a weblogic server

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

问题描述

使用以下代码,我能够连接到 weblogic 服务器.现在我想获取部署在服务器上的所有应用程序的列表.

Using the following code, I am able to connect to the weblogic server. Now I want to get a list of all the applications deployed on the server.

命令提示符中的listapplications() 列出了应用程序,但是当我执行interpreter.exec(listapplications()) 时,我无法将输出存储到变量中,因为interpreter.exec 返回一个void.关于如何将应用程序列表存储在集合/数组中的任何想法?

listapplications() from the command prompt lists the applications, but I am not able to store the output into a variable when I execute interpreter.exec(listapplications()) because interpreter.exec returns a void. Any ideas on how can I store the applications list in a collection/array?

任何其他替代方案或线索也会有所帮助.

Any other alternative or leads would also help.

import org.python.util.InteractiveInterpreter;
import weblogic.management.scripting.utils.WLSTInterpreter;

public class SampleWLST {

    public static void main(String[] args) {
        SampleWLST wlstObject = new SampleWLST();
        wlstObject.connect();
    }

    public void connect() {
        InteractiveInterpreter interpreter = new WLSTInterpreter();
        interpreter.exec("connect('username', 'password', 't3://localhost:8001')");
    }
}

推荐答案

我解决了.我通过使用 InteractiveInterpreter 的 setOut 方法重定向到流来捕获 wlst 的输出,并编写了一个扫描器来读取 Java 中的流.

I solved it. I captured the output of the wlst by redirect to a stream using setOut method of InteractiveInterpreter and wrote a scanner to read the stream in Java.

希望这可以帮助其他人.

Hope this might help someone else.

ArrayList<String> appList = new ArrayList<String>();
Writer out = new StringWriter();
interpreter.setOut(out);
interpreter.exec("print listApplications()");   

StringBuffer results = new StringBuffer();
results.append(out.toString());

Scanner scanner = new Scanner(results.toString());
while(scanner.hasNextLine()){
    String line = scanner.nextLine();
    line = line.trim();
    if(line.equals("None"))
        continue;
    appList.add(line);
}

这篇关于获取部署在 weblogic 服务器上的所有应用程序的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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