2013-01-24 32 views
4

使用以下代碼,我可以連接到weblogic服務器。 現在我想要獲取服務器上部署的所有應用程序的列表。獲取部署在weblogic服務器上的所有應用程序的列表

從命令提示符列表應用程序()列出應用程序,但我執行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')"); 
    } 
} 

回答

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); 
} 
相關問題