+ 1

how to write to/get input from console in Java?

So System.out.prntln is supposed to write things in console, it works when i am running my program in Eclipse IDE, but when im launching my program from the .jar file, console does not show up. Same with scanners - it gets user input if i run my program in IDE, but doesnt when i am running the exported .jar file is there a way to write/read stuff from console in java, same like cout/cin works in c++?

29th Jul 2018, 8:44 AM
Data
Data - avatar
5 odpowiedzi
+ 9
All you have to do, is execute your .jar file via command line, in order to get the console up and working. If you don't want to do that every time you run the program, create a batch/shell script which you can execute and automatically run the .jar via cmd. https://stackoverflow.com/questions/28477529/what-happens-to-system-out-println-in-executable-jar
29th Jul 2018, 8:51 AM
Hatsy Rei
Hatsy Rei - avatar
+ 4
Data Sorry for late follow-up, glad you managed to fix it. Is it possible to share what you did? Just in case anyone needs to refer to this thread in the future.
29th Jul 2018, 11:17 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
nevermind, found how to fix it. Thx for the answer with the command line
29th Jul 2018, 10:16 AM
Data
Data - avatar
+ 1
when exporting the project in Eclipse, there are 2 options to export to .jar file. One is called just "JAR file", other is called "Runnable JAR file". What i used before is the first option, exporting with the second one fixed the issue with "no manifest attribute". I from what i see, the second option writes down the name of the class with main function in MANIFEST.MF file in META-INF folder inside .jar file
29th Jul 2018, 11:31 AM
Data
Data - avatar
0
i tried executing .jar through the command line, it said "no main manifest attribute, in tee.jar". File name is tee.jar
29th Jul 2018, 10:00 AM
Data
Data - avatar