macos 相当于 Mac 上可双击的 .sh 和 .bat?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/589905/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Equivalent of double-clickable .sh and .bat on Mac?
提问by Epaga
I am distributing a Java program where I want a double-clickable file to run
我正在分发一个 Java 程序,我希望在其中运行一个可双击的文件
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?
在 Windows 上,我只是分发一个 .bat 文件,对于 *nix 一个可执行的 .sh 文件。问题是,双击 .sh 文件只会在 Mac 上的文本编辑器中打开它。我应该为 Mac 做什么?
回答by mouviciel
On mac, there is a specific extension for executing shell scripts by double clicking them: this is .command
.
在 mac 上,有一个特定的扩展名可以通过双击它们来执行 shell 脚本:这是.command
.
回答by Barry Wark
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.
对于 Mac 上的 Java 应用程序,您确实应该使用 Apple 的 Jar Bundler(在 Developer Tools/Applications/Utilities 文件夹中;实际上是 /usr/share/java/Tools/Jar Bundler 的符号链接)。它可以让您制作一个合适的 OS X 可双击应用程序,包括设置首选项,例如使用 Mac 工具栏、JVM 版本、图形系统、OS X 应用程序元数据和类路径/资源。
回答by Till
You can use a .sh (Shell Script), after all MacOSX is Unix!
您可以使用 .sh(Shell Script),毕竟 MacOSX 是 Unix!
回答by Noah
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.
关于使用 Jar Bundler 工具的答案是正确的,但是如果您想使用 .sh 文件,请确保使用 CHMOD 将 unix 权限正确设置为 755 之类的内容,并确保第一行包含安装的 shell 的路径默认在 Mac OS X 上。另请注意,即使设置了 +x 位,它仍可能询问用户是要打开它还是运行它。