eclipse中如何在运行时工作台(而不是开发工作台)的console中输出信息?

本文介绍如何将插件运行时的System.out和System.err信息输出到Eclipse工作台的默认控制台,避免创建新的控制台窗口。通过使用特定的代码片段,可以实现在指定的控制台名称下显示输出信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在我们运行一个插件时,代码中的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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值