Executing a jar on mac 10.8

梦想的初衷 提交于 2019-12-17 19:27:28

问题


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

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.

Ps. I have made jar files through the command line, bluej, and eclipse, none of these ways solved the issue.


回答1:


I would create a shell script to enclose it in terminal:

#!/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).




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/18858363/executing-a-jar-on-mac-10-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!