0

I created a program that is console based, but the problem I have is when (Through eclipse) I turn it into a runnable .jar file and run it, nothing happens. I believe this is because it is printing to the console but the .jar has no idea how it's supposed to show that. So my question is is there a way to redirect the console to a new window? I have seen similar questions but none of the methods seem to work. I cannot use the console because I plan on giving this to extended family that has no idea how to use it from the command prompt, and are not computer savvy Thanks!

Jacob R.
  • 7
  • 3

1 Answers1

3

Assuming you're using Windows, try running the jar from a console window thats already open:

java -jar myJar.jar

This will display the output in your existing console window.

You're not seeing anything when running the jar from the explorer because it finishes too fast and closes it's window upon completion before you can properly see it.

Marv
  • 3,517
  • 2
  • 22
  • 47
  • My problem with doing this is that I plan on giving this to my entire family, and that is not easy when my extended family is VERY extended. – Jacob R. Mar 16 '16 at 11:51
  • To force the window to stay open instead, you could add `Thread.sleep(Long.MAX_VALUE);` to the end of your program. – Marv Mar 16 '16 at 11:55
  • Where do you mean by 'end'? And when I try to rrun it from command prompt it just says 'Error: Unable to access jarfile ******.jar' – Jacob R. Mar 16 '16 at 14:29
  • With _at the end_ I mean at the very bottom of your `main()` method. Also: [Unable to access Jar File](http://stackoverflow.com/questions/11943948/error-unable-to-access-jar-file) – Marv Mar 16 '16 at 14:32
  • When I paste it in I get errors, I either have to put it in a try-catch statement or add something to my main method – Jacob R. Mar 16 '16 at 14:42
  • As for the directory, if I have a space in one of the files do I replace it with an underscore? – Jacob R. Mar 16 '16 at 14:46
  • No. Also, [spaces in filenames are a bad idea.](http://superuser.com/questions/29111/what-technical-reasons-exist-for-not-using-space-characters-in-file-names) – Marv Mar 16 '16 at 15:17
  • I have no choice =P It's the name of my PC – Jacob R. Mar 16 '16 at 23:03