Running a .jar file in a command prompt from double click

Nexus490 picture Nexus490 · May 14, 2013 · Viewed 11.5k times · Source

I'll start of by saying Im on windows 7.

I have created a .jar file which executes fine from the command line using the - java -jar myJar.jar approach

But what I'm after is to be able to double click on the jar file and for it to open up the command prompt window and run in the command prompt as if i've just typed the java -jar myJar.jar line.

When I double click the jar file I do think it is running because a visual part of the java is appearing, but there is no command prompt window showing my console output.

After looking around I've come across people saying that javaw which is what the jar files are associated with don't have a console and that I need to associate jar files with java.exe instead of javaw.exe. I've tried this and it didn't seem to work.

Can anyone help? A step by step would be nice.

Answer

user2439749 picture user2439749 · May 31, 2013

I had the same question and the bat file idea was genius and saved me a lot of time rewriting code. Thanks!(I would have upvoted,but apparently I don't have enough rep.)

Batch (or Bat) files are super easy to make.

Just put the java -jar YourFile.jar into notepad (if you're on windows), save as Title.bat, and put into the same folder as your jar.

presto! a program open-able by the general public.