如何将文件作为参数传递给使用JAR Bundler创建的Java应用程序? [英] How do I pass a file as argument to my Java application created using JAR Bundler?

查看:122
本文介绍了如何将文件作为参数传递给使用JAR Bundler创建的Java应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将特定文件类型与我的应用程序相关联,因此,当我双击该特定类型的文件之一时,我的应用程序将打开.效果很好,但是我双击的文件不会作为参数传递给程序.

例如,如果我将我的应用程序与txt文件相关联,并且双击todo.txt,则会打开我的应用程序,但是我不知道我双击了哪个txt文件.

据我了解,这是在OS X上工作的假定,而不是依靠默认行为(例如Windows上的工作方式),我应该使用此处的另一个问题,一个人说他在一些中文网站上找到了解决方案,而另一个人则说不是根据Java的许可协议条款是合法的.

Mac OS X开发人员库中,我找不到任何提及. ,而有关JAR Bundler的网站上的链接似乎有用,只是将我发送至 JAR Bundler ;一种Apple工具,专门用于能够将Java应用程序视为本机OS X应用程序.首先,使用此功能,我可以将文件类型与我的应用程序相关联.

解决方案

我使用了 com.apple.eawt.ApplicationListener 已过时,您可以尝试 com.apple.eawt.OpenFilesHandler 代替.

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.

解决方案

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.

这篇关于如何将文件作为参数传递给使用JAR Bundler创建的Java应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆