Installing and Running Java application on Macs
I have a java desktop application for which I am trying to create a Mac application package. The application is composed of two runnable jar files and several folders of text and images. The first jar acts as an updater and launcher for the second jar which is the bulk of the application. The application uses a variety of data files and images that are referenced in the application by relative path name (e.g. ./images/bits/xyz.jpg).
On Macs, however, I a开发者_C百科m having trouble getting the relative pathnames to work after creating a Application Bundle with Jar Bundler. I have no personal experience with Macs and need help understanding the standard way to laying out an application on them. I have noticed that other applications that I have installed come as a disk image file that opens with instructions to drag the app into the applications folder. I am trying to create a similar install package. Thank you in advance for your advice.
Drag and drop instruction in a disk image is a complete red herring. Once the app bundle is correctly made, it does not matter whether it's in the disk image or it's just zipped.
Note that on Macs, executables (whether native Cocoa or Java) don't have its current directory set to the path of the executable. So, you first need to get the current absolute path of the jar file, say. For that, there are already Q&As on Stack Overflow. See e.g. here.
You might need a Mac in order to create a proper Java Bundle and a DMG file. Here is a simple example:
http://www.centerkey.com/mac/java/
And here is a tutorial on how to make use of Mac-specific Swing features: http://java.sun.com/developer/technicalArticles/JavaLP/JavaToMac3/
As a developer with Pyxis Software, I would like to add that we have developed an application that solves this issue. The application named Pyxis Bundler will automatically bundle your jar file and optional libraries into a standard Mac application.
You can optionally embed the JRE from your JAVAHOME directory or select a specific JRE. While this will clearly enlarge the size of your application, the user does not need to have JAVA pre-installed on their machine to run your application.
There is also an option to create a modern Apple Icon image (multi size ICNS file).
We designed this as a replacement for the Jar Bundler application that used to be shipped with Xcode up to a number of years ago.
Pyxis Bundler saves each unique application settings to a preferences file, so if or when you update your Mac application, you only need to select the application name from a drop-down list to load all previously used data for that application. Then simply increment your version number and click the Create button.
I should add that with Pyxis Bundler you must use proper package names.
More information is available here: https://explorepyxis.com/shop http://www.pyxis.ie/explore/index.php/software/pyxis-jar-bundler
You can check-out how to name packages here: https://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html
精彩评论