I have a program without a GUI and I use console! So first I read a line from a user from console
BufferedReader userReader = new BufferedReader(new InputStreamReader(System.in));
and then I will write an answer for the user in the console!
System.out.println("Server:"+output);
I want to create a jar file for it ! but how can i show my console in jar file with out using GUI? please help me thanks.
First, there are no such things as "console JAR" and "GUI JAR". There are different VM launchers for console and GUI modes, though. Or, more precisely, there are different launchers one of which has console, the other one hasn't, but both of them are capable of displaying a GUI if your program has one. These launchers are named "java" (console version) and javaw (no console version).
To start a JAR with a specific launcher, use "javaw -jar JARFILE" or "java -jar JARFILE" command. If you start the console version without opening a console before doing it, then the console closes as soon as your program is finished. This means if you want to see your output you should either not terminate your program too quickly or just start a console first (Win+R, "cmd", Enter) and run "java -jar ..." from the console.
The other way is to go to the Windows Control Panel and change the program associated with the JAR extension from "javaw" to "java". This will make every JAR in the system use console. For JARs with GUI this will only introduce an inconvenience of having another window open. Sometimes it is what you want, sometimes not.
You need to run your jar file from CLI (command line). Like:
java -jar yourJar.jar
pause
If you want to force this, there are different ways to do this:
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