File to open terminal and run .jar on OSX?

I currently have a small text game written in Java that uses System.out.print(); to display text and Scanner to receive input from the user.

I compiled runnable.jar and used IExpress to create an .exe that runs the java -jar "foo.jar" after execution. This is not the best way to distribute the game, but it is a quick way to distribute it to friends for testing the game on Windows.

I am wondering if there is an equivalent for OSX? I know that I can write a shell script to open a terminal and execute a .jar file, but will it work if the shell script and .jar are distributed to other computers? Does everyone have to grant .sh permission to "execute"? Some of these people are not very tech savvy, and even mentioning the opening of the terminal will lead them to help me play the test.

So, is there a way to give them something double tap that will open a terminal and launch my .jar?

Thanks in advance!

+4
source share
1 answer

Here are two possible options (the first of which will probably not open the terminal, but I will leave here if you find a way to do this with the JarBundler below)

1 - Creating your own set of applications and the Java installer

The answer is several doubled. OSX applications have a specific directory structure that the operating system expects in place, they are called application packages (google for the "osx application programmer's guide" for dirty complex parts). Jar Bundler is an Ant task that can build a kit for you without requiring an understanding of the package format itself.

This is enough for you to drag and drop the application into the OSX dock. However, more common is the installer. To create an installer, you need to create a DMG file. Here you can find some good documentation on how to create this with Ant .

Its essence is to create a disk image, attach it to it, copy the application into it, disconnect it and compress it. A typical OSX installer is a window with a copy of your application and a symbolic link to the / Applications directory. When the installer window opens, it displays both of these elements, and you usually drag the application onto the / Applications icon, "installing it" (actually, just copying it to / Applications).

Below are the relevant Ant build files from my project for creating the application package , as well as creating the DMG file (both are links in Google code). They do not require any GUI tools.

Both of these files are quite heavily commented.

However, I feel that this will not open the terminal window as you wish (you can work with the stubfile parameter in JarBunder to make it do what you want).

2 - Create an application package from your shell script

This link shows how to create an application package from a shell script.

You can then create the DMG file from the application package to simplify the installation for your users. The DMG file will save the attributes of the execution file, so they will not need to manually chmod +x your script.

+1
source

Source: https://habr.com/ru/post/1403529/


All Articles