views:

39

answers:

2

I'm trying to use CFBundleDocumentTypes to associate a custom file extension with my application. As far as I can tell, this seems to "work" -- JavaApplicationStub launches my application when I double click the file. However, no callback is registered through the ApplicationListener events I setup in java.

I used the code listed in http://stackoverflow.com/questions/1460193/set-default-file-association-mac-os-x-java-package-maker-installer to do the file association, and the file association itself appears fine, but it seems as if it is the application stub trying to launch the file, and thus fails.

I added the Apple ApplicatinListener code to my java application at (similar to http://developer.apple.com/mac/library/documentation/Java/Reference/1.5.0/appledoc/api/index.html?com/apple/eawt/Application.html) but it doesn't seem like my application ever gets a call back.

the code is similar to
Application.getApplicatin().addApplicationListener(
new ApplicationAdapter() {
public void handleOpenFile(ApplicationEvent evt) { //some logging message here that I never get}
});

I should perhaps mention that I'm also using SWT...

Any help would be appreciated

+1  A: 

It's not very specific to your question, but a few things come to mind:

1) As you are using Apple's JavaApplicationStub, diagnostic output from the launch process may be obtained as follows:

$ export JAVA_LAUNCHER_VERBOSE
$ ./your.app/Contents/MacOS/JavaApplicationStub

2) You might look at Apple's example application, OSXAdapter, mentioned here.

3) Here's a working example of an SWT/Java/Mac application.

trashgod
+1  A: 

Unfortunately you can't use the SWT and the eAWT's ApplicationListener at the same time. See this SWT bug. The SWT needs a change from Apple in the JVM, and then I have to change the SWT to use it.

Since you are interested in an open file event, though, you can now do that entirely in SWT across all platforms. In the 3.6 SWT there is a new event SWT.OpenDocument that will fire when a file for your app is double-clicked. See this blog post and search for "SWT.OpenDocument".

Scott K.