Java JNLP桌面快捷方式和图标

时间:2012-03-02 01:25:31

标签: java swing desktop-application jnlp

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 个答案:

答案 0 :(得分:1)

要使用Java Web Start启动打开关联文件,请使用传递给main(String[] args)的参数数组的第二个元素。第一个元素将是&#34; -open&#34;当您通过双击文件启动应用程序时,args [1]存储我们要在启动时打开的文件的文件路径。此功能确实使Java应用程序感觉像本机桌面应用程序。

我无法在JNLP文档中找到这个。

以下是实现此功能的示例主要方法。 FileFunction是一个具有应用程序文件I / O的静态方法的类。

public static void main(String[] args) {
    GUI win = new GUI(null);
    if(args.length==2) {
        win = new GUI(null);
        StringBuilder params = new StringBuilder();
        for(String s : args) {
            params.append(s);
            params.append("\n");
        }
        JOptionPane.showMessageDialog(null, params);
        try {
            FileFunction.loadList(new FileInputStream(new File(args[1])));
        }
        catch(IOException ioe) {
            FileFunction.showFileError(ioe);
        }
    }