Java – System.out.println() does not print to the console in Eclipse

System.out.println() does not print to the console in Eclipse… here is a solution to the problem.

System.out.println() does not print to the console in Eclipse

I’m using Cucumber, Selenium, and JUnit in Java to develop test automation scripts. To quickly detect any issues with my custom code, I set System.out.println(“success”) and System.err.println("failure"). Put it in some places. The problem is that neither prints to the console in Eclipse. While not necessarily using these tools, I’ve done it hundreds of times. I suspect Cucumber or JUnit are the culprit, but after a Google query I couldn’t find anything that confirmed this.

I did see this :

System.out.println doesn’t print anything inside eclipse console

But that’s not a problem. None of my consoles show my println().

Update what I’ve tried so far :

  1. PrintStream out = System.out; system.setOut(out); System.out.println("Hello");
  2. Eclipse Console not showing output
  3. Throws an exception explicitly (resulting in no stack trace in the console).

Solution

As it turned out, there was a bug in the version of Eclipse Oxygen I was using. Typically, when you run code in Eclipse, the code executes as javaw.exe not java.exe. The only difference between the two is that javaw.exe does not use the CMD console, while java.exe uses the CMD console. Usually Eclipse will be executed using javaw because it has its own console, but some versions of Eclipse (which may just be Oxygen) have a known bug that Eclipse does not handle correctly, so you need to make it use java instead. To this end:

Go to Run > Run Configuration > Make sure that the desired class with the main method is selected on the left> Select the JRE on the right> Click Alternate JRE under the Runtime JRE section> Under Java Executable, select Alternate and type Java to apply > live

enter image description here

Related Problems and Solutions