Get a list of all applications deployed on a weblogic server

Using the following code, I can connect to the weblogic server. Now I want to get a list of all the applications deployed on the server.

listapplications () from the command line lists the applications, but I cannot store the output in a variable when interpreter.exec (listapplications ()) is executed, because interpreter.exec returns a void. Any ideas on how to keep the list of applications in a collection / array?

Any other alternative or conclusions will also help.

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')"); } } 
+4
source share
1 answer

I solved it. I captured wlst output by redirecting to a stream using the setOut InteractiveInterpreter method and wrote a scanner to read the stream in Java.

Hope this helps someone else.

 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); } 
+3
source

All Articles