18

Although this seems like a rather obvious question, I couldn't find the answer anywhere online.

After I create the jar file, I can run it successfully using the command line by saying

java -jar filename.jar

However, I want this file to be a bit more user-friendly, in other words, run on double click. For some reason when I double click the jar file the mac jar launcher (Jar\ Launcher.app) opens, pauses one second then closes. I appreciate the help.

Ps. I have made jar files through the command line, bluej, and eclipse, none of these ways solved the issue.

1
  • Does your JAR reference resource files, such as images? Perhaps when you double-click it the working directory is in a different location. Also you may want to try opening /Applications/Utilities/Console -- there may be an error message there. Sep 17, 2013 at 21:29

3 Answers 3

14

I would create a shell script to enclose it in terminal:

#!/bin/bash
java -jar yourjarfile.jar
read -p 'Hit [Enter] to continue...'

I added pause, but unless your java application is immediately reaching termination, it shouldn't be necessary (you can stop the shell script after the "java" line).

2
  • Hi, Rogue. Thanks for the advice. Right now I have a temporary file (a .command file that runs my jar file on double click).
    – JFakult
    Sep 18, 2013 at 19:10
  • Nice, I believe you can add the "read -p" as well to pause it in .command, which will let you see runtime errors.
    – Rogue
    Sep 19, 2013 at 15:39
2

There is a program on OS X called Jar Bundler that comes with your install of Xcode developer tools. You can use this to convert .jar files to native Mac OS X .app executables.

4
  • I am aware of the Jar Bundler application, I forgot to mention it but that didn't solve my issue, thanks though.
    – JFakult
    Sep 17, 2013 at 19:36
  • It seems like exactly what you want, but no worries. Sep 17, 2013 at 19:39
  • Jar Bundler is long since deprecated. Sep 17, 2013 at 21:30
  • Yeah, the jar bundler did the same thing as the jar launcher, it opened, paused a second then exited.
    – JFakult
    Sep 18, 2013 at 19:09
1

You need Java WebStart, snippet from the link Java Web Start software provides the power to launch full-featured applications with a single click. Users can download and launch applications, such as a complete spreadsheet program or an Internet chat client, without going through lengthy installation procedures

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.