使用以下代码,我可以连接到weblogic服务器。 现在我想获得服务器上部署的所有应用程序的列表。
来自命令提示符的listapplications()列出了应用程序,但是当我执行interpreter.exec(listapplications())时,我无法将输出存储到变量中,因为interpreter.exec返回一个void。关于如何将应用程序列表存储在集合/数组中的任何想法?
任何其他替代方案或潜在客户也会有所帮助。
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')");
}
}
答案 0 :(得分: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);
}
答案 1 :(得分: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);
您将需要的依赖项:
编译(组:'com.oracle.weblogic',名称:'wlfullclient',版本:'10 .3.6.0',可传递:false)