views:

739

answers:

4

I am distributing a Java program where I want a double-clickable file to run

java -cp MyProgram.jar;MyLib.jar my.program.Main

On Windows I simply distribute a .bat file, for *nix an executable .sh file. Problem is, double-clicking the .sh file just opens it up in a text editor on Mac. What should I do for Mac?

A: 

You can use a .sh (Shell Script), after all MacOSX is Unix!

Till
+5  A: 

On mac, there is a specific extension for executing shell scripts by double clicking them: this is .command.

mouviciel
works like a charm!
Epaga
+2  A: 

For Java applications on Mac, you really should use Apple's Jar Bundler (in the Developer Tools/Applications/Utilities folder; really a symlink to /usr/share/java/Tools/Jar Bundler). It lets you make a proper OS X double-clickable app, including setting preferences for e.g. using the Mac toolbar, JVM version, graphics system, OS X app metadata and classpath/resources.

Barry Wark
+1  A: 

The answer about using the Jar Bundler tool is correct, but if you want to use a .sh file, make sure the unix permissions are set properly to something like 755 with CHMOD, and make sure the first line contains the path to a shell installed by default on Mac OS X. Also note that even with the +x bit set, it may still ask the user whether they want to open it or run it.

Noah