Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing a jar on mac 10.8

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.

like image 631
JFakult Avatar asked Sep 17 '13 19:09

JFakult


People also ask

How do I force a JAR file to open on a Mac?

Answer: A: Try selecting the . jar file, command-I to open the Get Info window, and see what is chosen for "Open With". You should be able to choose "Jar Launcher", since you have Java installed.

Can Mac use JAR files?

For the uninitiated, to run JAR files, you have to ensure that Java is pre-installed on your Mac. Both JRE (Java Runtime Environment) and JDK (Java Development Kit) can be compatible programs.


2 Answers

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).

like image 90
Rogue Avatar answered Oct 09 '22 02:10

Rogue


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.

like image 35
Hunter McMillen Avatar answered Oct 09 '22 02:10

Hunter McMillen