我有一個通過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一無所知。
***可能涉及[Java小應用程序依賴項被多次讀取](h TTP://stackoverflow.com/q/15029510/418556)。 – 2013-02-22 19:52:19