Java通过JNLP与用户的桌面操作系统很好地集成 . 我的软件不仅显示为桌面图标,而且还在控制面板(Windows 7)中列为已安装的程序 . 我还能够获取JNLP文件以自动配置文件关联 . 现在,如果用户双击我的程序保存的文件(pxml文件),程序将启动 . JNLP通过网络发布使这种出色的桌面集成顺利进行 . 还有一个问题:如何让我的程序加载用户双击的数据文件? pxml文件与我的程序具有相同的图标,并且JNLP创建了文件关联,因此当用户尝试打开pxml文件时,Windows知道启动我的软件 . 但是,当程序启动时,我的程序如何知道打开该文件?
以下是JNLP文件的一部分供参考,取自Proctinator.com
<jnlp spec="6.0+" codebase="http://proctinator.com/dist" >
<information>
<title>The Proctinator</title>
<vendor>Smart Software Solutions, INC.</vendor>
<homepage href="http://proctinator.com"/>
<description kind="short">The Proctinator exam scheduling software</description>
<icon kind="splash" href="splashScreen.jpg" />
<icon kind="shortcut" href="bigP.jpg" />
<offline-allowed/>
<association extensions="pxml" mime-type="application/pxml"/>
<shortcut online="false">
<desktop/>
</shortcut>
</information>
<resources> <j2se version="1.6+"/> ... </resources>
<application-desc main-class="thornworks.proctor.GUI"/>
1 回答
要使用Java Web Start启动打开关联文件,请使用传递给
main(String[] args)
的参数数组的第二个元素 . 通过双击文件启动应用程序时,第一个元素将是"-open",而args [1]存储我们要在启动时打开的文件的文件路径 . 此功能确实使Java应用程序感觉像本机桌面应用程序 .我在JNLP文档中找不到这个 .
以下是实现此功能的示例主要方法 . FileFunction是一个具有应用程序文件I / O的静态方法的类 .