I have a JavaFX 8 desktop application and I'm creating an .app
application bundle to distribute the application to Mac users. I use the Oracle “Self-Contained Application Packaging” tool to generate the bundle.
The problem that I have relates to the files associated with my application. I am associating the extension .wordy
with these files. If I have the application open and I double click one of these files in the Mac Finder, my application receives an OpenFilesEvent
containing the path to the file and everything works perfectly. If, however, the application is not open, double clicking a .wordy
file in the Finder opens my application as I would expect but I never receive the event containing the path to the file that the user double-clicked on.
The file association is done in the Ant script for the Oracle “Self-Contained Application Packaging” tool, as follows:
<project name="VocabHunter Packaging" basedir=""
xmlns:fx="javafx:com.sun.javafx.tools.ant">
...
<fx:info title="VocabHunter">
<fx:association description="VocabHunter session"
extension="wordy"
mimetype="application/x-vnd.VocabHunterSession"
icon="${basedir}/icons/mac/VocabHunterSession.icns"/>
</fx:info>
...
</project>
In the Java code, I obtain an instance of com.apple.eawt.Application
and then register the listener for the OpenFilesEvent
as follows:
Application application = Application.getApplication();
application.setOpenFileHandler(new OsxOpenFilesHandler(listener));
You can see the full code here.
Does anyone know how to fix this so that I receive an event containing the path to the .wordy
file even if the application was not running at the moment that the file was double clicked?
In the interests of completeness, I'm using the Oracle JDK 1.8.0_66 for Mac.