如何将文件作为参数传递给使用 JAR Bundler 创建的 Java 应用程序?

发布于 2024-12-05 12:25:57 字数 2006 浏览 4 评论 0 原文

我想将特定文件类型与我的应用程序关联,因此当我双击该特定类型的文件之一时,我的应用程序将打开。这工作得很好,但是我双击的文件没有作为参数传递给我的程序。

例如,如果我将我的应用程序与 txt 文件关联,然后双击 todo.txt,我的应用程序将打开,但我不知道哪个 txt > 文件我双击。

据我所知,这就是它在 OS X 上的工作方式,而不是依赖默认行为(它在 Windows 等上的工作方式),我应该使用 ApplicationListener.handleOpenFile(); 来自 com.apple.eawt。然而,当我尝试这样做时,我被告知我不允许这样做:

访问限制:由于类型 ApplicationListener 无法访问 对所需库的限制 /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/ui.jar

这里还有一个问题,一个人说他在某中文网站,另一个说根据Java的许可协议条款不合法。

我在 Mac OS X 开发人员库 中找不到任何提及它的内容这个关于 JAR Bundler 的网站上的链接可能看起来很有用,只是将我发送到 Apple 开发者网站上的死页

我缺少什么?即使这在其他操作系统上微不足道,是否应该几乎不可能做到这一点?

这可能值得一提...由于 JAR 文件无法与 OS X 上的程序关联,因此我创建了一个 OS X 应用程序包 使用 JAR捆绑器;专门为能够将 Java 应用程序视为本机 OS X 应用程序而制作的 Apple 工具。使用它首先允许我将文件类型与我的应用程序关联起来。

I would like to associate a specific file type with my application, so when I double-click one of the files of this specific type, my application opens. This works just fine, but the file I double-clicked does not get passed as an argument to my program.

If I for instance associate my application with txt files and I double-click todo.txt, my application opens, but I have no idea which txt file I double-clicked.

From what I can read, this is how it's supposed to work on OS X, and instead of relying on the default behaviour (how it works on e.g. Windows), I should use ApplicationListener.handleOpenFile(); from com.apple.eawt. When I attempt this, however, I'm being told that I'm not allowed to do so:

Access restriction: The type ApplicationListener is not accessible due
to restriction on required library
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/ui.jar

In another question here, one guy says he found the solution on some Chinese website, and the other says it isn't legal according to Java's license agreement terms.

I can find no mention of it in the Mac OS X Developer Library, and whatever links might seem useful on this site about JAR Bundler just sends me to a dead page on Apple's Developer site.

What am I missing? Is it supposed to be nearly impossible to do this, even though it's trivial on other operating systems?

It's probably worth mentioning... since JARfiles can't be associated with programs on OS X, I've created an OS X Application Bundle using JAR Bundler; an Apple tool made specifically for the purpose of being able to treat Java applications as native OS X applications. Using this is what allowed me to associate the file type with my application in the first place.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

是你 2024-12-12 12:25:57

I've used OSXAdapter for preferences, about, and quit functionality. You might be able to leverage it's introspective approach to avoid the restriction. As com.apple.eawt.ApplicationListener is deprecated, you might try com.apple.eawt.OpenFilesHandler instead.

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