简体   繁体   English

在Mac上,如何创建将包含.jar文件,打开终端并运行该.jar文件的图标?

[英]On a Mac, how do I create icon that will take a .jar file, open a terminal, and run that .jar file?

Long story short, I have created a text-based-game, and I want to make it easily transferable to friends' computers. 长话短说,我已经创建了一个基于文本的游戏,并且我想使其易于转移到朋友的计算机上。

I don't want to have to give instructions on how to open a terminal and run the file. 我不想给出有关如何打开终端并运行文件的说明。 Can you provide step-by-step instructions on how to (at the minimum) be able to double click the DustToDiamonds.jar file to have it run in the terminal or to (ideally) be able to create an actual icon to be pressed which causes a terminal to open and run the game? 您能否提供有关如何(至少)如何双击DustToDiamonds.jar文件以使其在终端中运行或(理想情况下)能够创建要按下的实际图标的分步说明?导致终端打开并运行游戏?

As of now, when I double click on the .jar file I get a popup window with the following error: "The Java JAR file "DustToDiamonds.jar" could not be launched . Check the Console for possible error messages." 到目前为止,当我双击.jar文件时,出现一个弹出窗口,并显示以下错误: "The Java JAR file "DustToDiamonds.jar" could not be launched 。请在控制台中查找可能的错误消息。”

I used eclipse to create a .jar for me, and when I run jar -jar DustToDiamonds.jar in the terminal it runs. 我使用eclipse为我创建了一个.jar,当我在终端中运行jar -jar DustToDiamonds.jar时,它将运行。 I don't know anything about Application Bundling or shell commands, so if those are necessary I would need actual code to work off of. 我对应用程序捆绑或Shell命令一无所知,因此,如果有必要,我将需要实际的代码来解决。 I am using a Mac running El Capitan. 我正在使用运行El Capitan的Mac。

Thanks in advance! 提前致谢!

You can use some 3rd-party solution to bundle your application into an executable. 您可以使用某些第三方解决方案将您的应用程序捆绑为可执行文件。 For example, you can try a packr . 例如,您可以尝试使用packr

Earlier, it was passible to use a JarBundler, but it is not provided with newest version of MacOS. 以前,使用JarBundler是可以通过的,但最新版本的MacOS并未提供它。 If you, possibly, use a Gradle as build tool, you can use this plugin to create executable .app. 如果可能,请使用Gradle作为构建工具,则可以使用此插件来创建可执行文件.app。 There is like the same solution for the Ant scripts and I suppose you can find something for Maven, if you need it. 类似的解决方案也适用于Ant脚本 ,我想如果需要的话,您可以为Maven找到一些解决方案。

As an alternative, you can create a shell script, like for any unix-system, and make it executable. 作为替代方案,您可以像创建任何unix系统一样,创建一个shell脚本并使之可执行。 You van find an example here . 您可以在此处找到示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM