我想将特定文件类型与我的应用程序关联,因此当我双击该特定类型的文件之一时,我的应用程序将打开。这工作得很好,但是我双击的文件没有作为参数传递给我的程序。
例如,如果我将我的应用程序与 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 JAR
files 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.
发布评论
评论(1)
我使用过
OSXAdapter
用于首选项、关于和退出功能。您也许可以利用它的内省方法来避免限制。作为com .apple.eawt.ApplicationListener
已弃用,您可以尝试com.apple. eawt.OpenFilesHandler
代替。I've used
OSXAdapter
for preferences, about, and quit functionality. You might be able to leverage it's introspective approach to avoid the restriction. Ascom.apple.eawt.ApplicationListener
is deprecated, you might trycom.apple.eawt.OpenFilesHandler
instead.