获取部署在weblogic上的所有应用程序的列表

2024-10-01 09:42:18 发布

您现在位置:Python中文网/ 问答频道 /正文

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

当我无法从应用程序的输出列表中存储一个变量时,我不能从应用程序中存储一个变量解释器.exec(listapplications())因为解释器.exec返回一个空值。关于如何将应用程序列表存储在集合/数组中有什么想法吗?在

任何其他的选择或线索也会有所帮助。在

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')");
    }
}

Tags: import服务器应用程序列表newconnectpublic解释器
2条回答

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

希望这能对其他人有所帮助。在

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

要获取所有展开的文章,可以使用:

private void listAllDeployments(WebLogicDeploymentManager deployManager,
                                  Target targets[]) throws TargetException {
  if (deployManager != null && targets.length > 0) {
    print("Get Domain:" + deployManager.getDomain(), 0);
    TargetModuleID targetModuleID[] = deployManager.getAvailableModules(ModuleType.WAR, 
      targets);
    } else {
      System.out.print(
        "WebLogicDeploymentManager is either empty or targets are empty.Please check",
        1);
    }

  }

要创建deployer manager,可以使用:

^{pr2}$

您将需要的依赖项:

编译(组:'com.oracle.weblogic,名称:“wlfullclient”,版本:“10.3.6.0”,可传递:false)

相关问题 更多 >