相当于 Mac 上可双击的 .sh 和 .bat?
我正在分发一个 Java 程序,我希望在其中运行一个可双击的文件。
java -cp MyProgram.jar;MyLib.jar my.program.Main
在 Windows 上,我只需分发一个 .bat 文件,*nix 为一个可执行的 .sh 文件。 问题是,双击 .sh 文件只会在 Mac 上的文本编辑器中将其打开。 我应该为 Mac 做什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 Mac 上,有一个通过双击执行 shell 脚本的特定扩展:这是
.command
。On mac, there is a specific extension for executing shell scripts by double clicking them: this is
.command
.对于 Mac 上的 Java 应用程序,您确实应该使用 Apple 的 Jar Bundler(位于 Developer Tools/Applications/Utilities 文件夹中;实际上是到 /usr/share/java/Tools/Jar Bundler 的符号链接)。 它可以让您制作适当的 OS X 双击应用程序,包括设置首选项,例如使用 Mac 工具栏、JVM 版本、图形系统、OS X 应用程序元数据和类路径/资源。
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.
您可以使用 .sh(Shell 脚本),毕竟 MacOSX 是 Unix!
You can use a .sh (Shell Script), after all MacOSX is Unix!
关于使用 Jar Bundler 工具的答案是正确的,但如果您想使用 .sh 文件,请确保将 unix 权限正确设置为带有 CHMOD 的 755 之类的内容,并确保第一行包含已安装 shell 的路径Mac OS X 上默认情况下。另请注意,即使设置了 +x 位,它仍然可能会询问用户是否要打开它或运行它。
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.