2013-02-22 90 views
0

我有一個通過PHP腳本創建的JNLP文件。它輸出類似如下文件:Java Web Start - 忽略/更改JAR href URL

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<jnlp codebase="/" spec="1.0+"> 
    <information> 
     <title>sometitle</title> 
     <vendor>somevendor</vendor> 
     <homepage href=""/> 
     <description>somedesc</description> 
     <description kind="short">someshort</description> 
    </information> 
    <update check="always"/> 
    <security> 
<all-permissions/> 
</security> 
    <resources> 
     <j2se version="1.7+"/> 
     <jar href="http://fproject.localhost/getjava/jar/e43e034c49c4a24f2711d385370faaf1ef92ca76" main="true"/> 
     <jar href="http://fproject.localhost/getjava/libs/lib/commons-codec-1.6.jar" main="true"/> 
     <jar href="http://fproject.localhost/getjava/libs/lib/commons-logging-1.1.1.jar" main="true"/> 
     <jar href="http://fproject.localhost/getjava/libs/lib/fluent-hc-4.2.3.jar" main="true"/> 
     <jar href="http://fproject.localhost/getjava/libs/lib/httpclient-4.2.3.jar" main="true"/> 
     <jar href="http://fproject.localhost/getjava/libs/lib/httpclient-cache-4.2.3.jar" main="true"/> 
     <jar href="http://fproject.localhost/getjava/libs/lib/httpcore-4.2.2.jar" main="true"/> 
     <jar href="http://fproject.localhost/getjava/libs/lib/httpmime-4.2.3.jar" main="true"/> 
    </resources> 
    <application-desc main-class="Windows8.Windows8GUI"> 

    </application-desc> 
</jnlp> 

應用程序加載和最初打開正常,但是應用程序緩慢,反應遲鈍,在我的Apache訪問日誌服用後一看似乎有一些怪現象,以及第一所有,它加載所有罐子成功:

127.0.0.1 - - [22/Feb/2013:19:39:56 +0000] "GET /getjava/libs/lib/fluent-hc-4.2.3.jar HTTP/1.1" 200 24509 "-" "JNLP/1.7.0 javaws/10.13.2.20 (<internal>) Java/1.7.0_13" 
127.0.0.1 - - [22/Feb/2013:19:39:56 +0000] "GET /getjava/libs/lib/commons-logging-1.1.1.jar HTTP/1.1" 200 65294 "-" "JNLP/1.7.0 javaws/10.13.2.20 (<internal>) Java/1.7.0_13" 
127.0.0.1 - - [22/Feb/2013:19:39:56 +0000] "GET /getjava/jar/ba1df5097852421a791d095271fd48df6c79804c HTTP/1.1" 200 14060 "-" "JNLP/1.7.0 javaws/10.13.2.20 (<internal>) Java/1.7.0_13" 
127.0.0.1 - - [22/Feb/2013:19:39:56 +0000] "GET /getjava/libs/lib/commons-codec-1.6.jar HTTP/1.1" 200 253503 "-" "JNLP/1.7.0 javaws/10.13.2.20 (<internal>) Java/1.7.0_13" 
127.0.0.1 - - [22/Feb/2013:19:39:57 +0000] "GET /getjava/libs/lib/httpclient-4.2.3.jar HTTP/1.1" 200 469073 "-" "JNLP/1.7.0 javaws/10.13.2.20 (<internal>) Java/1.7.0_13" 
127.0.0.1 - - [22/Feb/2013:19:39:57 +0000] "GET /getjava/libs/lib/httpclient-cache-4.2.3.jar HTTP/1.1" 200 124242 "-" "JNLP/1.7.0 javaws/10.13.2.20 (<internal>) Java/1.7.0_13" 
127.0.0.1 - - [22/Feb/2013:19:39:57 +0000] "GET /getjava/libs/lib/httpcore-4.2.2.jar HTTP/1.1" 200 245191 "-" "JNLP/1.7.0 javaws/10.13.2.20 (<internal>) Java/1.7.0_13" 
127.0.0.1 - - [22/Feb/2013:19:39:57 +0000] "GET /getjava/libs/lib/httpmime-4.2.3.jar HTTP/1.1" 200 29955 "-" "JNLP/1.7.0 javaws/10.13.2.20 (<internal>) Java/1.7.0_13" 

再就是對同一文件的請求的負載,但位置已經改變:

127.0.0.1 - - [22/Feb/2013:19:40:02 +0000] "GET /getjava/jar/lib/fluent-hc-4.2.3.jar HTTP/1.1" 404 2011 "-" "Java/1.7.0_13" 
127.0.0.1 - - [22/Feb/2013:19:40:03 +0000] "GET /getjava/jar/lib/httpclient-4.2.3.jar HTTP/1.1" 404 2011 "-" "Java/1.7.0_13" 
127.0.0.1 - - [22/Feb/2013:19:40:03 +0000] "GET /getjava/jar/lib/httpclient-cache-4.2.3.jar HTTP/1.1" 404 2011 "-" "Java/1.7.0_13" 
127.0.0.1 - - [22/Feb/2013:19:40:03 +0000] "GET /getjava/jar/lib/httpclient-4.2.3.jar HTTP/1.1" 404 2011 "-" "Java/1.7.0_13" 
127.0.0.1 - - [22/Feb/2013:19:40:03 +0000] "GET /getjava/jar/lib/httpclient-4.2.3.jar HTTP/1.1" 404 2011 "-" "Java/1.7.0_13" 
127.0.0.1 - - [22/Feb/2013:19:40:04 +0000] "GET /getjava/jar/lib/fluent-hc-4.2.3.jar HTTP/1.1" 404 2011 "-" "Java/1.7.0_13" 
127.0.0.1 - - [22/Feb/2013:19:40:04 +0000] "GET /getjava/jar/lib/httpclient-4.2.3.jar HTTP/1.1" 404 2011 "-" "Java/1.7.0_13" 
127.0.0.1 - - [22/Feb/2013:19:40:05 +0000] "GET /getjava/jar/lib/httpclient-cache-4.2.3.jar HTTP/1.1" 404 2011 "-" "Java/1.7.0_13" 
127.0.0.1 - - [22/Feb/2013:19:40:05 +0000] "GET /getjava/jar/lib/httpcore-4.2.2.jar HTTP/1.1" 404 2011 "-" "Java/1.7.0_13" 
127.0.0.1 - - [22/Feb/2013:19:40:05 +0000] "GET /getjava/jar/lib/httpmime-4.2.3.jar HTTP/1.1" 404 2011 "-" "Java/1.7.0_13" 
127.0.0.1 - - [22/Feb/2013:19:40:06 +0000] "GET /getjava/libs/lib/httpclient-cache-4.2.3.jar HTTP/1.1" 200 124242 "-" "JNLP/1.7.0 javaws/10.13.2.20 (<internal>) Java/1.7.0_13" 
127.0.0.1 - - [22/Feb/2013:19:40:06 +0000] "GET /getjava/libs/lib/httpcore-4.2.2.jar HTTP/1.1" 200 245191 "-" "JNLP/1.7.0 javaws/10.13.2.20 (<internal>) Java/1.7.0_13" 
127.0.0.1 - - [22/Feb/2013:19:40:06 +0000] "GET /getjava/jar/lib/fluent-hc-4.2.3.jar HTTP/1.1" 404 2011 "-" "Java/1.7.0_13" 
127.0.0.1 - - [22/Feb/2013:19:40:06 +0000] "GET /getjava/jar/lib/httpclient-4.2.3.jar HTTP/1.1" 404 2011 "-" "Java/1.7.0_13" 
127.0.0.1 - - [22/Feb/2013:19:40:07 +0000] "GET /getjava/jar/lib/httpclient-cache-4.2.3.jar HTTP/1.1" 404 2011 "-" "Java/1.7.0_13" 
127.0.0.1 - - [22/Feb/2013:19:40:07 +0000] "GET /getjava/jar/lib/httpcore-4.2.2.jar HTTP/1.1" 404 2011 "-" "Java/1.7.0_13" 
127.0.0.1 - - [22/Feb/2013:19:40:07 +0000] "GET /getjava/jar/lib/httpmime-4.2.3.jar HTTP/1.1" 404 2011 "-" "Java/1.7.0_13" 
127.0.0.1 - - [22/Feb/2013:19:40:08 +0000] "GET /getjava/jar/lib/fluent-hc-4.2.3.jar HTTP/1.1" 404 2011 "-" "Java/1.7.0_13" 
127.0.0.1 - - [22/Feb/2013:19:40:08 +0000] "GET /getjava/jar/lib/httpclient-4.2.3.jar HTTP/1.1" 404 2011 "-" "Java/1.7.0_13" 

請注意,/ getjava/libs/lib已更改爲/ getjava/jar/lib

這是怎麼回事? JVM從哪裏獲取此URL?

還有更多,爲什麼JVM一遍又一遍地請求同一個文件?

編輯 - 更多信息

我想我已經縮小的問題倒一點點。我很確定這是與Netbeans有關。我使用的是7.2.1版本。

似乎額外庫請求的URLs來自主應用程序Jar中的META-INF/MANIFEST.MF文件。在那裏我可以看到以下內容:

Class-Path: lib/commons-codec-1.6.jar lib/commons-logging-1.1.1.jar li 
b/fluent-hc-4.2.3.jar lib/httpclient-4.2.3.jar lib/httpclient-cache-4 
.2.3.jar lib/httpcore-4.2.2.jar lib/httpmime-4.2.3.jar 

這可以解釋修改後的網址和隨後404級的響應,因爲這些文件未提供該網址。

我不明白爲什麼Netbeans創建這個路徑的文件。我的印象是Java Webstart使用JNLP文件下載資源,並且使用<resources>節點?

如何阻止netbeans添加此Class-Path屬性,因爲我相信這是我的問題的根源。

進一步更新

我已經穿過文件黑客發現了這個問題一個解決辦法。如果我拿出這一行:

<attribute name="Class-Path" value="${jar.classpath}"/> 

此文件:

nbproject\build-impl.xml   

然後Netbeans的正確編譯的Jar了Webstart的應用程序。它不會在Jar中的META-INF/MANIFEST.MF文件中創建Class-Path屬性。刪除後,該應用程序工作絕對好,沒有掛起和不存在的文件沒有假的請求。

現在我想問的是,爲什麼Netbeans會這樣做?有沒有適當的解決辦法,而不是我駭客關於XML配置文件?請記住,我一直在使用Java一個星期左右。我對ANT/Java一無所知。

+0

***可能涉及[Java小應用程序依賴項被多次讀取](h TTP://stackoverflow.com/q/15029510/418556)。 – 2013-02-22 19:52:19

回答

0

試試這個:

  • 使用http://fproject.localhost/getjava的代碼庫jnlp元素
  • 使用上的資源相對路徑(即<jar href="libs/lib/commons-logging-1.1.1.jar"/>
  • 不要把main="true"無處不在,但只有罐子包含主類Windows8.Windows8GUI
+0

刪除main =「true」會產生另一個消息。我知道他們本來不應該去那裏,那是一個複製粘貼錯誤。新的錯誤是在罐子加載後提供的:http://i49.tinypic.com/2iths7.png。還值得注意的是,刪除庫並只留下主類來修復無緩存問題。但顯然,我需要他們。 – 2013-02-22 21:43:52

+0

您是否嘗試在更改JNLP文件後清除Java應用程序緩存? – 2013-02-23 08:59:17

+0

不知道這是可能的。問題是每次加載JNLP都會被更改,它會在主類Jar的URL中使用新的哈希更新。可以停止緩存嗎? – 2013-02-23 10:29:39