在我们运行一个插件时,代码中的System.out和System.err等信息都输出到了我们进行插件开发的工作台中,而没有输出到我们运行插件的工作台中,如果我们想让它在运行时工作台中输出,而且想让它在运行时工作台中默认的console中输出,即不想再新建一个console,那我们可以用以下的代码来实现预期的想法:
private MessageConsole findConsole(String name) {
ConsolePlugin plugin = ConsolePlugin.getDefault();
IConsoleManager conMan = plugin.getConsoleManager();
IConsole[] existing = conMan.getConsoles();
for (int i = 0; i < existing.length; i++)
if (name.equals(existing[i].getName()))
return (MessageConsole) existing[i];
//no console found, so create a new one
MessageConsole myConsole = new MessageConsole(name, null);
conMan.addConsoles(new IConsole[]{myConsole});
return myConsole;
}
MessageConsole myConsole = findConsole(CONSOLE_NAME);
MessageConsoleStream out = myConsole.newMessageStream();
out.println("Hello from Generic console sample action");
本文参考自:http://wiki.eclipse.org/FAQ_How_do_I_write_to_the_console_from_a_plug-in%3F