JavaApplicationStub with CFBundleDocumentTypes

家住魔仙堡 提交于 2019-12-24 10:38:50

问题


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 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.getApplication().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:


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".




回答2:


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.



来源:https://stackoverflow.com/questions/3033948/javaapplicationstub-with-cfbundledocumenttypes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!