获取Weblogic服务器上部署的所有应用程序列表
我用下面的代码成功连接到了weblogic服务器。现在我想获取服务器上所有已部署的应用程序的列表。
在命令提示符下使用listapplications()可以列出这些应用程序,但当我执行interpreter.exec(listapplications())时,无法将输出存储到一个变量中,因为interpreter.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')");
}
}
2 个回答
0
要获取所有已经部署的工件,你可以使用:
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);
}
}
要创建部署管理器,你可以使用:
SessionHelper.getRemoteDeploymentManager(protocol,hostName, portString, adminUser, adminPassword);
你需要的依赖项:
compile(group: 'com.oracle.weblogic', name: 'wlfullclient', version: '10.3.6.0', transitive: false)
3
我解决了这个问题。我通过使用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);
}