带有 CFBundleDocumentTypes 的 JavaApplicationStub
我正在尝试使用 CFBundleDocumentTypes 将自定义文件扩展名与我的应用程序关联。据我所知,这似乎“有效”——当我双击该文件时,JavaApplicationStub 会启动我的应用程序。但是,没有通过我在 java 中设置的 ApplicationListener 事件注册回调。
我使用了 设置默认文件关联中列出的代码Mac OS X Java Package Maker Installer 进行文件关联,文件关联本身看起来很好,但似乎是应用程序存根试图启动文件,因此失败。
我将 Apple ApplicatinListener 代码添加到我的 java 应用程序中(类似于 http://developer.apple.com/mac/library/documentation/Java/Reference/1.5.0/appledoc/api/index.html? com/apple/eawt/Application.html),但我的应用程序似乎没有收到回调。
代码类似于
Application.getApplication().addApplicationListener(
new ApplicationAdapter() {
public void handleOpenFile(ApplicationEvent evt) {
//some logging message here that I never get
}
}
);
我也许应该提到我也在使用 SWT...
任何帮助将不胜感激
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,您不能同时使用 SWT 和 eAWT 的 ApplicationListener。请参阅此 SWT 错误。 SWT 需要 Apple 在 JVM 中进行更改,然后我必须更改 SWT 才能使用它。
不过,由于您对打开文件事件感兴趣,因此您现在可以在所有平台上完全在 SWT 中执行此操作。在 3.6 SWT 中,有一个新事件
SWT.OpenDocument
,当双击应用程序的文件时将触发该事件。请参阅此博客文章并搜索“SWT.OpenDocument”。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".这对你的问题来说不是很具体,但我想到了一些事情:
1)当你使用Apple的
JavaApplicationStub
,可以按如下方式获取启动过程的诊断输出:2) 您可以查看 Apple 的示例应用程序 OSXAdapter,提到在这里。
3) 这是一个 SWT/Java/Mac 应用程序的工作示例。
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:2) You might look at Apple's example application, OSXAdapter, mentioned here.
3) Here's a working example of an SWT/Java/Mac application.