A simple example to make a Mac OS X application from generated binary file
Introduction
A generated binary file of GUI application for Mac OS X can be launched directly, but it is not a kind of Mac OS X application. To be a Mac OS X application, we need to put it into an ".app" folder before we deploy it.
Solution
We just need to create an ".app" folder, and then put an "Info.plist" file in it and put the generated binary file into the 'MacOS' sub-folder, then modify the "Info.plist" to let it know the filename of the generated binary file.
Features used
We advise you to use following features:
Feature | Advice | Introduction | How to enable |
---|---|---|---|
GUI application |
Required |
If your program is not GUI application, usually you need not to put it into an '.app' folder. |
At Step 2, select Windows GUI |
Splash window |
Recommended |
To display a splash window is more friendly. This can tell user the program is starting. |
At Step 3, select a picture |
Optional |
If your program need to run in a certain "working directory", you can enable "Force CWD" to ignore the start position. |
At Step 6 > Config Internal > Custom tab, use a 'forcecwd' item |
|
Stdout redirect |
Optional |
Because the console window is not visible, if you need to get the content of System.out, you can redirect it to a disk file. |
At Step 6 > Config Internal > Custom tab, use a 'stdout' item |
Steps
Steps of this advice:
- The demo program is a simple calculator. ( Source code)
- Compile and pack into a jar file: SimpleCalc.jar. ( Jar file)
-
Build a binary file for Mac OS X from jar file by Jar2Exe
- Start Jar2Exe, at step 1, click Browse Jar and select SimpleCalc.jar.
- Still at step 1, select Mac as target platform.
- At step 2, select Windows GUI application.
- At step 6, please check "Create Universal Binary", to create a binary with both 32 and 64 cores.
- Click next until finish, then get the binary file 'SimpleCalc' for Mac OS X.
- For other options, please refer to other solutions.
-
Make a Mac OS X application from the binary file
- Make an empty folder, for example "./Calc/"
- Make a sub-folder 'Contents'.
- Make a sub-folder 'MacOS' and put the binary file in it, so we get "./Calc/Contents/MacOS/SimpleCalc".
- Add the 'execute' privilege to 'SimpleCalc' by 'chmod +x SimpleCalc' because windows filesystem could not express 'x'.
-
Make a text file './Calc/Contents/Info.plist' with following content:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleExecutable</key> <string>SimpleCalc</string> <key>NSHighResolutionCapable</key> <true/> </dict> </plist>
- Rename the folder "./Calc" to "./Calc.app"
-
Icon of Mac ".app" folder, the icon file of ".app" folder is a ".icns" file, which means "icons" in one file.
- Put the ".icns" file into sub-folder 'Resources', for example: "./Calc/Contents/Resources/SimpleCalc.icns".
-
Specify the icon filename in 'Info.plist' file:
<key>CFBundleIconFile</key> <string>SimpleCalc.icns</string>
Download
- You can download this demo program here.
- solutions-all.zip - 11.3M, all solution related files in one file.
Comments
No such file or directory
My app read data from file txt in same folder with jar file. when I make app file on Mac and run it. It error :
./file_data/useragents.txt (No such file or directory)
How can I fix it.
Having troubles running Mac OS binary
Hello, I have been having troubles running the generated binary for Mac, this is after I turn on the execute flag with "chmod +x" an then run.
I have generated a Windows .exe with the same jar file that starts and performs as it should, but on Mac I get a java.lang.ExceptionInitializerError every time the program gets to the new FXMLLoader(url) part of my code. I have tried to look to at the URL by printing it out before loading and I noticed it had the format "j2e:com/xxxx/xxxx/xxxx.fxml" and I'm quite sure I have the "com/xxxx/xxxx/xxxx.fxml" resource file in the jar I provided.
The code below is how i am getting the fxml file in my code.
URL url = getClass().getClassLoader().getResource("com/xxxx/xxxx/xxxx.fxml");
Could you send the demo jar files
And the created mac binary file
Where to put the jre directory on Mac ?
Hi, where to put the jre directory when bundle .app is used? inside MacOS directory?
thank you
you really need to update your doc pages on website to add Mac OS X information... ;)
Regards
Any where if you use a 'jre' config item to specify it
You can add a config file "./Calc/Contents/MacOS/SimpleCalc.config" and use a "jre" item to specify the location of jre directory by a relative path from the "SimpleCalc" to the jre directory.
For example, if you put 'jre/' to "./Calc/Contents/jre", then you can use "jre ../jre/".
Please refer to http://www.jar2exe.com/createdexe/config/jre
executable won't run
Hi. When i try to generate a macos executable, the file doesn't appear as an executable when i copy it to my mac.
I opened up the .app file from your calculator example, and extracted the executable file from that, and am able to double click it outside the .app file to start it.
However, when i double click my own executable file, it opens up in a text editor. It doesn't appear to be recognized as an executable at all.
Any idea what i'm doing wrong? My executable is generated using jar2exe on my windows machine using the macos setting in the wizard. I've been able to get both linux and windows versions working just fine.
I found the solution...
I found the solution...
https://macosx.com/threads/change-a-plain-text-file-to-unix-executable-f...
Open Terminal.
type...chmod +x
...with a space at the end (and do NOT press enter yet).
Then, drag the file you want to change from the Finder and drop it on top of the Terminal window. The file path and filename should automatically fill in (and you should ensure that there's a space between "+x" and the file path).
Press enter.
This changes the file to an executable.
I'm having the same problem.
I'm having the same problem. When I generate a MacOS file and copy it to the Mac the Mac thinks it's a text file. I also tried a Linux file and it also shows as a text file on the Mac.
Problem to Create App
I follow all steps but when I open the App I get a error message: The application “Launcher.app” can’t be opened.
I tried open the files on MacOS 10.10 and 10.11.2 and still doesn't work.
Any idea what could be?
Add new comment