Java – open the terminal and start it in OSX Jar file?
I currently have a small text game written in Java, which uses system out. print(); Output text and scanner to receive input from the user
I compiled runnable Jar and created one using Iexpress Exe, which runs the batch command Java - jar "foo. Jar" at execution time This is not the best way to distribute games, but it is a quick way to distribute them to friends for game testing in windows
I wonder if OSX has the same function? I know I can write a shell script to open the terminal and execute it Jar file, but if the shell script and Jar is distributed to other computers. Will it work? Everyone must give SH file "execute" permission? Some of them are not really proficient in technology, and even mention that open terminals will make them refuse to participate in the test
So there's no way to give them some double clicks, which will open the terminal and run mine jar?
Thank you in advance!
Solution
Here are two possible options (the first may not open the terminal, but I will leave here in case you find a method through the jarbundler mentioned below)
1 – build native Java application packages and installers
The answer is a bit twofold OSX applications have a specific directory structure expected by the operating system. They are called application packages (Google's "OSX application package programmer's Guide" for cluttered and complex details) Jar bundler is an ant task that can build a package for you without unpacking the format itself
This alone is enough for you to drag the application onto the OSX base However, it is more common to install programs To build the installer, you need to build the DMG file Some good documents on how to use ant can be found here to create this document
Its main point is to create a disk image, attach it, copy the application into it, detach and compress it A typical OS X installer is a window that contains a copy of the application and a symbolic link to the / applications directory When the installer window opens, it displays these two items. You usually drag the application to the / Applications Icon and "install it" (in fact, just copy it to / Applications)
The following is my project building an application bundle and related ant build files of building a DMG file (both are google code links) They do not require any GUI tools
Both documents contain many comments
However, I have a feeling that this will not open the terminal window as you want (you can use the stub file option in jarbunder to make it do what you want)
2 – create application package from shell script
This link shows you how to create an application package from a shell script
You can then create DMG files from the application package to simplify user installation DMG files will retain the properties of the executable file, so they don't need to Chmod x your script manually