【问题标题】:Why isn't this printing to the console in Eclipse?为什么不打印到 Eclipse 中的控制台?
【发布时间】:2012-11-01 08:56:34
【问题描述】:

鉴于这段代码,我很困惑为什么它不打印到控制台......

    engine.compileTemplate(new PrintWriter(System.err));
    System.err.flush();

我在控制台上什么也看不到。 System.out 也有同样的问题。是的,我通过成功打印到文件来验证代码是否有效。

【问题讨论】:

    标签: java eclipse io


    【解决方案1】:

    尝试使用constructor with autoflush。您正在刷新 System.err,而不是 PrintWriter。

    【讨论】:

    • 是的,但是你应该刷新 PrintWriter,而不是 System.err?
    【解决方案2】:

    这段代码在什么上下文中执行? 确实需要更多信息来确定发生了什么。

    您的代码是否在您正在调试的插件中运行? 如果是这样,那么使用“打印到控制台” - 您是指与您的插件相同的 Eclipse 实例的控制台吗?

    为此,您需要执行以下操作:

    MessageConsole console = new MessageConsole("My Console", null);
    console.activate();
    ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[]{ console });
    MessageConsoleStream consoleStream = console.newMessageStream();
    consoleStream.println("Hello, world!");
    

    否则,它会转到启动 Eclipse 的控制台。

    在此处阅读更多信息:http://wiki.eclipse.org/FAQ_How_do_I_write_to_the_console_from_a_plug-in%3F

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-15
      • 2020-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-08
      相关资源
      最近更新 更多