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?
Info from some answers after the question: BAT file was an attempt to bring to MS-DOS something like the idea of the UNIX script. the text file as executable (rather than give it a specific suffix). This is how OS X does it.
macOS - How to execute a shell script with a double clickMost of use use the extension ". sh" for a shell script, but this could be associated with a text editor like BBEdit (highly recommended and there is a free version). So instead of running the script, it will open it in your text editor.
Easiest way for a lazy Mac user like me: Drag-and-drop the startup.sh file from the Finder to the Terminal window and press Return. To shutdown Tomcat, do the same with shutdown.sh . You can delete all the . bat files as they are only for a Windows PC, of no use on a Mac to other Unix computer.
sh script on macOS. Shell scripts are normally written and run on Linux systems but they're almost as at home on a Mac system as they are on a Linux system. You can write a Shell script on macOS, and you can run it easily, far more easily than you can on a Windows 10 system.
On mac, there is a specific extension for executing shell scripts by double clicking them: this is .command
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With