Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

How would I make an executable jar open a command prompt window?

I have my program in an executable jar, which has output from System.out.println(). However unless someone goes into cmd/terminal and runs it, the output doesn't appear anywhere, even though it's running (making it a lot more difficult to close as well). I was wondering how I could make it open a command prompt window on startup so that the output could always appear, regardless to if it were run in cmd/terminal or if it were just double-clicked.
As an alternative to that, you could make it open a JFrame with an info field that you use instead of System.out.println.
(Nov 28, 2013 09:45 AM)кovu Wrote:  As an alternative to that, you could make it open a JFrame with an info field that you use instead of System.out.println.

That sounds like it could work as well. How would I go about doing that?
make a batch file:

@echo off
java -jar jarFile.jar
pause

put this in the notepad and save it as:

run.bat

Then run it with the jar file located locally
(Nov 28, 2013 09:46 AM)ImportUsername Wrote:  That sounds like it could work as well. How would I go about doing that?

Make a JFrame, add a label or text field. Then, just .add() to it the system.out.printlns.
(Nov 28, 2013 10:32 AM)3 Kings Wrote:  make a batch file:

@echo off
java -jar jarFile.jar
pause

put this in the notepad and save it as:

run.bat

Then run it with the jar file located locally

Thats missing the whole point of having an executable jar.
(Nov 28, 2013 08:36 PM)Manthe Wrote:  Thats missing the whole point of having an executable jar.

Not really. You are using a bat file to open the executable.

That's like saying "using the mouse to double-click and execute it" is missing the whole point of having an executable jar.
Runtime.getRuntime().exec("cmd /c start");
I also think you can add "echo" and the text you want, if you place it behind start in the runtime command[/quote]
I think its that 🤝


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Shell] by Robert RougeSep 24, 2026 10:03 AM 1 298 Sep 24, 2026 10:03 AM
Last Post: Anonynuk
[Java] by ThatDevAaronOct 12, 2021 12:47 PM 5 159 Oct 12, 2021 12:47 PM
Last Post: ThatDevAaron
[Shell] by ImDeepWithWindowsJul 4, 2020 06:19 PM 0 167 Jul 4, 2020 06:19 PM
Last Post: ImDeepWithWindows