我想在我的java程序中获取mvndependency:tree输出。我可以使用以下代码将输出输出到文本文件。
try {
InvocationRequest request = new DefaultInvocationRequest();
request.setPomFile(new File("C:\\Users\\Dexter\\pom.xml"));
request.setGoals(Arrays.asList("dependency:tree"));
Invoker invoker = new DefaultInvoker();
//invoker.setOutputHandler(request);
try(PrintWriter log = new PrintWriter("C:\\Users\\Dexter\\ty.txt")) {
InvocationOutputHandler outputHandler = new InvocationOutputHandler() {
@Override
public void consumeLine(String s) {
log.println(s);
}
};
request.setOutputHandler(outputHandler);
System.out.println();
InvocationResult result = invoker.execute(request);
}
catch (Exception e){
System.out.println(e);
}
//System.out.println(result);
}
catch (Exception e){
System.out.println(e);
}
我想将输出输出到程序内部。我的意思是像清单之类的。我该怎么办?