Java – How to run other main class during runtome and get it’s console output


I have a list of jars that contains jar with needed main-class.
I try to run it main class:

public static void runCommandlineMain(String classPathFile, String args[]) throws Exception{
    URL[] urls = getJarUrls(classPathFile);
    URLClassLoader classLoader = new URLClassLoader(urls);

    Class<?> clazz = classLoader.loadClass("liquibase.commandline.Main");
    Method main = clazz.getMethod("main", String[].class);
    main.invoke(null, new Object[]{args});

But after run I've follow:

Process finished with exit code -1

and nothing more.
How can i resolve it? And how to get console out put from this class?

Best Solution

Didn't quite get your first question.

But, to answer your second question: "How do you get console output"

try the StreamGobbler here

Related Question