带有 CFBundleDocumentTypes 的 JavaApplicationStub

发布于 2024-09-05 11:35:52 字数 1055 浏览 7 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

墨离汐 2024-09-12 11:35:52

不幸的是,您不能同时使用 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".

玩物 2024-09-12 11:35:52

这对你的问题来说不是很具体,但我想到了一些事情:

1)当你使用Apple的 JavaApplicationStub,可以按如下方式获取启动过程的诊断输出:

$ export JAVA_LAUNCHER_VERBOSE
$ ./your.app/Contents/MacOS/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:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文