System.out.println() 不打印到 Eclipse 中的控制台
System.out.println() does not print to the console in Eclipse
我正在 Java 中使用 Cucumber、Selenium 和 JUnit 开发测试自动化脚本。为了快速检测我的自定义代码的任何问题,我在某些地方放置了 System.out.println("success")
和 System.err.println("failure")
。问题是既不打印到 Eclipse 中的控制台。虽然不一定使用这些工具,但我已经完成了数百次。我怀疑 Cucumber 或 JUnit 是罪魁祸首,但在一些 Google 查询后我找不到任何证实这一点的东西。
我确实看到了这个:
System.out.println doesn't print anything inside eclipse console
但这不是问题所在。 None 我的控制台正在显示我的 println()。
更新到目前为止我尝试过的内容:
PrintStream out = System.out; System.setOut(out); System.out.println("hello");
- Eclipse Console not showing output
- 明确抛出异常(导致控制台中没有堆栈跟踪)
它是否适用于 Eclipse 中的一个不相关的项目,但不适用于您当前的项目?我假设您使用的一些库代码调用 System.setOut()
(和 Err 类似)来更改打印流。您可以尝试的是:
PrintStream out = System.out;
...
insert your library calls here
....
System.setOut(out);
System.out.println("Test out println");
事实证明我使用的 Eclipse 版本 (Eclipse Oxygen) 存在错误。通常,当在 Eclipse 中执行 运行 代码时,代码将作为 javaw.exe 而不是 java.exe 执行。这两者之间的区别仅在于 javaw.exe 不使用 CMD 控制台,而 java.exe 使用 CMD 控制台。通常 Eclipse 将使用 javaw 执行,因为它有自己的控制台,但是某些 Eclipse 版本存在一个已知错误,可能只是 Oxygen,Eclipse 无法正确处理此问题,因此您需要使其使用 java 代替。为此:
转到 运行 > 运行 配置 > 确保所需的 class 和主要方法在左侧 selected > select JRE在右侧 > 单击 运行time JRE 部分下的 Alternate JRE > select 在 Java executable 下交替并在字段中键入 "java" > Apply
我正在 Java 中使用 Cucumber、Selenium 和 JUnit 开发测试自动化脚本。为了快速检测我的自定义代码的任何问题,我在某些地方放置了 System.out.println("success")
和 System.err.println("failure")
。问题是既不打印到 Eclipse 中的控制台。虽然不一定使用这些工具,但我已经完成了数百次。我怀疑 Cucumber 或 JUnit 是罪魁祸首,但在一些 Google 查询后我找不到任何证实这一点的东西。
我确实看到了这个:
System.out.println doesn't print anything inside eclipse console
但这不是问题所在。 None 我的控制台正在显示我的 println()。
更新到目前为止我尝试过的内容:
PrintStream out = System.out; System.setOut(out); System.out.println("hello");
- Eclipse Console not showing output
- 明确抛出异常(导致控制台中没有堆栈跟踪)
它是否适用于 Eclipse 中的一个不相关的项目,但不适用于您当前的项目?我假设您使用的一些库代码调用 System.setOut()
(和 Err 类似)来更改打印流。您可以尝试的是:
PrintStream out = System.out;
...
insert your library calls here
....
System.setOut(out);
System.out.println("Test out println");
事实证明我使用的 Eclipse 版本 (Eclipse Oxygen) 存在错误。通常,当在 Eclipse 中执行 运行 代码时,代码将作为 javaw.exe 而不是 java.exe 执行。这两者之间的区别仅在于 javaw.exe 不使用 CMD 控制台,而 java.exe 使用 CMD 控制台。通常 Eclipse 将使用 javaw 执行,因为它有自己的控制台,但是某些 Eclipse 版本存在一个已知错误,可能只是 Oxygen,Eclipse 无法正确处理此问题,因此您需要使其使用 java 代替。为此:
转到 运行 > 运行 配置 > 确保所需的 class 和主要方法在左侧 selected > select JRE在右侧 > 单击 运行time JRE 部分下的 Alternate JRE > select 在 Java executable 下交替并在字段中键入 "java" > Apply