A little disappointed that I couldn't find some content on my own website, this article is essentially just a pointer to another article, so ...
If you happen to be writing a Mac Java program (a Java/Swing program for a Mac OS X system), and you want to be able to right-click on a file, and see your Java application in the Mac Open menu (specifically the "Open With" menu), what you need to do is edit your Java app's info.plist file. This is the file that tells the Mac operating system that your Java application would like to be registered as a handler for specific file types.
Associating Mac files (file extensions) with your Mac Java application
Now, if you don't happen to know what a Java info.plist file is, fear not, you don't need to know too much. The important things to know are:
- You can build your Mac Java application with Ant build scripts. I link to several of those below.
- With your Mac Java Ant build scripts, you need to use the Mac JarBundler task, and specifically need to use the JarBundler DocumentType task. In this task you set the "name" attribute to the filename extensions your Java application should be associated with. For instance, if your Java application should be associated with file extensions like ".txt" and ".rtf", you specify these in the JarBundler DocumentType name attribute.
- The JarBundler task does all the hard work of building your Java application into what appears to be a native Mac application. This includes the creation of the info.plist file, which JarBundler builds for you. Again, the info.plist file will contain the filename extensions you specify.
Mac, Java, Ant, JarBundler, and info.plist tutorials
Now, getting to the meat of all this, here are links to all the Mac Java tutorials I've written, including the information on associated files with your Mac Java application, the info.plist file, the DocumentType task, and other things I couldn't find very easily:
- A complete Mac Java Ant JarBundler build script
- A Java Mac Dock drag and drop application and build script
- A Mac Java Ant build script, including JarBundler, info.plist, file associations, file extensions, and DocumentType examples
Finally, on the JarBundler website, this information on Associating files with your application is also an extremely helpful reference.
Hopefully all these links and keywords will help everyone find these Ant, JarBundler, Mac Dock, info.plist, file association (filename extensions), right-click, popup menu, and Mac Java file/open tutorials.