2012-03-02 138 views
1

Java通過JNLP與用戶的桌面操作系統很好地集成。 我的軟件不僅顯示爲桌面圖標,而且在控制面板中列爲已安裝程序(Windows 7)。我也能夠獲得JNLP文件來自動配置文件關聯。現在,如果用戶雙擊我的程序(一個pxml文件)保存的文件,程序將啓動。通過網絡發佈,JNLP可以使這種出色的桌面整合順利進行。 還有一個問題:如何讓我的程序加載用戶雙擊的數據文件? pxml文件被賦予與我的程序相同的圖標,並且JNLP創建了文件關聯,因此Windows知道在用戶嘗試打開pxml文件時啓動我的軟件。但是,我的程序在啓動時如何知道打開該文件?Java JNLP桌面快捷方式和圖標

下面是引用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"/> 

+0

從來沒有嘗試過,但這不會得到只是作爲您的main()方法的參數傳遞? – mikera 2012-03-02 01:32:41

+0

JNLP無效(並且格式錯誤),請嘗試使用[JaNeLA](http://pscode.org/janela/)進行檢查。 – 2012-03-02 06:30:17

+0

Andrew - 上面的XML不是整個文件。你確定JaNeLA是最新的並且認識到用1,6引入的新語法嗎? – Thorn 2012-03-02 11:12:40

回答

1

拍攝要打開與Java Web Start的推出相關的文件,使用傳遞給參數數組的第二個元素main(String[] args)。當您通過雙擊文件啓動應用程序時,第一個元素將是「-open」,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); 
     } 
    } 
相關問題