I am trying to write Java console application, the code is quite simple:
public class ConsoleTest {
public static void main(String[] args) {
System.out.println("test");
}
}
If I run this application from Eclipse, then i see "test
" in Eclipse's "Console", but if I export my app as a "Runnable JAR file" and run it from Windows XP cmd.exe
, then nothing is echoed to the console.
On the safe side, i tried to check System.console()
, it returns null
.
What can be wrong?
System. out. println does not print to the console, it prints to the standard output stream ( System. out is Java's name of the standard output stream).
Invoke the out() method of the System class, pass the PrintStream object to it. Finally, print data using the println() method, and it will be redirected to the file represented by the File object created in the first step.
The println is a method of java. io. PrintStream. This method is overloaded to print message to output destination, which is typically a console or file.
How are you running your program outside eclipse?
You should use command line like
java -jar yourjar.jar
or
java -cp yourjar.jar ConsoleTest
If you are occasionally using javaw
instead no console output will be produced. The STDOUT of javaw
is null
. Probably this is what happens when you are clicking on your jar file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With