Java 获取部署在weblogic服务器上的所有应用程序的列表
使用以下代码,我能够连接到weblogic服务器。 现在我想获得服务器上部署的所有应用程序的列表 命令提示符下的listapplications()列出了应用程序,但在执行解释器.exec(listapplications())时,无法将输出存储到变量中,因为解释器.exec返回一个空值。关于如何将应用程序列表存储在集合/数组中,有什么想法吗 任何其他替代方案或线索也会有所帮助Java 获取部署在weblogic服务器上的所有应用程序的列表,java,python,weblogic,weblogic-10.x,wlst,Java,Python,Weblogic,Weblogic 10.x,Wlst,使用以下代码,我能够连接到weblogic服务器。 现在我想获得服务器上部署的所有应用程序的列表 命令提示符下的listapplications()列出了应用程序,但在执行解释器.exec(listapplications())时,无法将输出存储到变量中,因为解释器.exec返回一个空值。关于如何将应用程序列表存储在集合/数组中,有什么想法吗 任何其他替代方案或线索也会有所帮助 import org.python.util.InteractiveInterpreter; import weblo
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中的流 希望这能帮助其他人
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);
}
ArrayList appList=new ArrayList();
Writer out=新的StringWriter();
出发(出发);
explorer.exec(“打印列表应用程序()”);
StringBuffer结果=新建StringBuffer();
results.append(out.toString());
Scanner Scanner=新扫描仪(results.toString());
while(scanner.hasNextLine()){
字符串行=scanner.nextLine();
line=line.trim();
如果(行等于(“无”))
继续;
添加(行);
}
要获取所有已部署的Articat,您可以使用:
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,可以使用:
SessionHelper.getRemoteDeploymentManager(protocol,hostName, portString, adminUser, adminPassword);
您将需要的依赖项:
编译(组:'com.oracle.weblogic',名称:'wlfullclient',版本:'10.3.6.0',可传递:false)