Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...