0

我有一个通过 PHP 脚本创建的 JNLP 文件。它输出类似于以下文件的内容:

<?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 访问日志后,似乎发生了一些奇怪的事情,首先,它成功加载了所有 jar:

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。

似乎额外库请求的 URL 来自META-INF/MANIFEST.MF主应用程序 Jar 中的文件。在那里我可以看到以下内容:

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

这将解释修改后的 URL 和随后的 404 响应,因为这些文件在该 URL 上不可用。

我不明白为什么 Netbeans 会创建这些文件路径。我的印象是 Java Webstart 使用 JNLP 文件下载其资源,并且在该<resources>节点中?

我怎样才能停止 netbeans 添加这个Class-Path属性,因为我相信这是我的问题的根源。

进一步更新

我通过破解文件找到了解决此问题的方法。如果我取出这条线:

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

从这个文件:

nbproject\build-impl.xml        

然后 Netbeans 为 Webstart 应用程序正确编译 Jar。它不会在 Jar 内的文件中创建Class-Path属性。META-INF/MANIFEST.MF删除此应用程序后,该应用程序工作得非常好,没有挂起,也没有对不存在的文件的虚假请求。

现在我想问题是,Netbeans 为什么要这样做?是否有适当的解决方法,而不是我破解 XML 配置文件?请记住,我已经使用 Java 大约一周了。我真的对 ANT/Java 一无所知。

4

1 回答 1

0

尝试这个:

  • 用作元素http://fproject.localhost/getjava的代码库jnlp
  • 在资源上使用相对路径(即<jar href="libs/lib/commons-logging-1.1.1.jar"/>
  • 不要main="true"到处放,只放包含主类的jarWindows8.Windows8GUI
于 2013-02-22T21:12:20.673 回答