Java 在 mac 10.8 上执行 jar
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18858363/
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
Executing a jar on mac 10.8
提问by JFakult
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
创建jar文件后,我可以使用命令行成功运行它,说
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.
但是,我希望这个文件对用户更加友好,换句话说,双击运行。出于某种原因,当我双击 jar 文件时,mac jar 启动器 (Jar\ Launcher.app) 会打开,暂停一秒钟然后关闭。我很感激你的帮助。
Ps. I have made jar files through the command line, bluej, and eclipse, none of these ways solved the issue.
附言。我已经通过命令行、bluej 和 eclipse 制作了 jar 文件,这些方法都没有解决问题。
回答by Sajan Chandran
You need Java WebStart, snippet from the link Java Web Start software provides the power to launch full-featured applications with a single click. Users can download and launch applications, such as a complete spreadsheet program or an Internet chat client, without going through lengthy installation procedures
您需要Java WebStart,来自链接的片段Java Web Start software provides the power to launch full-featured applications with a single click. Users can download and launch applications, such as a complete spreadsheet program or an Internet chat client, without going through lengthy installation procedures
回答by Hunter McMillen
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.
OS X 上有一个名为的程序Jar Bundler
,它随您安装的 Xcode 开发人员工具一起提供。您可以使用它来将 .jar 文件转换为原生 Mac OS X .app 可执行文件。
回答by Rogue
I would create a shell script to enclose it in terminal:
我会创建一个 shell 脚本将它包含在终端中:
#!/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).
我添加了暂停,但除非您的 java 应用程序立即终止,否则没有必要(您可以在“java”行之后停止 shell 脚本)。