Applet 由 Java Web Start 提供服务,在查看 JAR 文件之前向 WEB 服务器请求资源
我是新来的,我为我的英语不好而道歉。
我对 Java Web Start 技术提供的 Applet 类有一个小问题。我有一些依赖于平台的 JAR 文件,Web Start 可以正确下载,但是当我通过 ClassLoader 对象的 getResourceAsStream(String fileName) 方法获取内容时,首先发出 GET 请求fileName
到 WEB Server,收到 404 Not Found
响应后,资源从 JAR 文件中正确加载。问题是我的 JAR 中有很多文件,所以我在 WEB 服务器上有很多不必要的负载,因此我必须等待很长时间才能使用 Applet。
在Google上搜索我发现了一些讨论,其中据说添加了值为false
的参数codebase_lookup
,但这并没有解决问题。 此页面,与codebase_lookup 参数表示 Applet 的默认行为是从 JAR 文件加载资源,然后从 Applet 代码库加载资源,在我的例子中,行为是相反的。
我还在 .jnlp
文件中为每个 JAR 资源添加了 eager="true"
属性,但行为始终相同。 Applet是使用NetBeans开发和构建的,生成的html和jnlp文件如下。
launch.html
<applet width="300" height="300">
<param name="jnlp_href" value="launch.jnlp"/>
<param name="codebase_lookup" value="false"/>
</applet>
launch.jnlp
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jnlp codebase="http://192.168.23.4/contact" href="launch.jnlp" spec="1.0+">
<information>
<title>ContactNR</title>
<vendor>Roberto Santini</vendor>
<homepage href=""/>
<description>ContactNR</description>
<description kind="short">ContactNR</description>
</information>
<resources>
<j2se version="1.5+"/>
<jar eager="true" href="ContactNR.jar" main="true"/>
<jar eager="true" href="lib/VDK.jar"/>
<security>
<all-permissions/>
</security>
</resources>
<resources arch="amd64" os="Linux">
<jar eager="true" href="lib/liblinux64.jar"/>
</resources>
<resources arch="x86_64" os="Linux">
<jar eager="true" href="lib/liblinux64.jar"/>
</resources>
<resources arch="x86" os="Linux">
<jar eager="true" href="lib/liblinux.jar"/>
</resources>
<resources arch="i386" os="Linux">
<jar eager="true" href="lib/liblinux.jar"/>
</resources>
<resources os="Windows">
<jar eager="true" href="lib/libwin.jar"/>
</resources>
<resources os="MacOs">
<jar eager="true" href="lib/libmac.jar"/>
</resources>
<applet-desc height="300" main-class="com.netresults.voip.ContactNR" name="ContactNR" width="300">
<param name="codebase_lookup" value="false"/>
</applet-desc>
</jnlp>
有人可以帮助我吗? 非常感谢,
罗伯托。
I am new here and I apologize for my bad English.
I have a little problem with an Applet class served by Java Web Start technology. I have some platform dependent JAR files which Web Start download correctly, but when I get the content by getResourceAsStream(String fileName)
method of ClassLoader
object, first is made a GET request of fileName
to WEB Server, after received a 404 Not Found
response, the resource is loaded correctly from JAR file. The problem is that I have many files inside the JAR, so I have a lot of unnecessary load on the WEB Server and consequently I have to wait for long time before I can use the Applet.
Searching on Google I have found some discussions where it was said to add the parameter codebase_lookup
with value false
, but this has not solved the problem. This page, in relation to the codebase_lookup
parameter, says that the default behavior of an Applet is to load resources from JAR file and then from the Applet codebase, in my case the behavior is the opposite.
I also added the eager="true"
attribute for each JAR resource in the .jnlp
file, but the behavior is always the same. The Applet was developed and built with NetBeans, the html and jnlp files generated are the following.
launch.html
<applet width="300" height="300">
<param name="jnlp_href" value="launch.jnlp"/>
<param name="codebase_lookup" value="false"/>
</applet>
launch.jnlp
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jnlp codebase="http://192.168.23.4/contact" href="launch.jnlp" spec="1.0+">
<information>
<title>ContactNR</title>
<vendor>Roberto Santini</vendor>
<homepage href=""/>
<description>ContactNR</description>
<description kind="short">ContactNR</description>
</information>
<resources>
<j2se version="1.5+"/>
<jar eager="true" href="ContactNR.jar" main="true"/>
<jar eager="true" href="lib/VDK.jar"/>
<security>
<all-permissions/>
</security>
</resources>
<resources arch="amd64" os="Linux">
<jar eager="true" href="lib/liblinux64.jar"/>
</resources>
<resources arch="x86_64" os="Linux">
<jar eager="true" href="lib/liblinux64.jar"/>
</resources>
<resources arch="x86" os="Linux">
<jar eager="true" href="lib/liblinux.jar"/>
</resources>
<resources arch="i386" os="Linux">
<jar eager="true" href="lib/liblinux.jar"/>
</resources>
<resources os="Windows">
<jar eager="true" href="lib/libwin.jar"/>
</resources>
<resources os="MacOs">
<jar eager="true" href="lib/libmac.jar"/>
</resources>
<applet-desc height="300" main-class="com.netresults.voip.ContactNR" name="ContactNR" width="300">
<param name="codebase_lookup" value="false"/>
</applet-desc>
</jnlp>
Can someone help me?
Thanks at all,
Roberto.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通过向 JAR 文件添加索引解决了这个问题。
构建 jar 后,运行命令:
它必须作为实际 JAR 编译的单独步骤运行。
解释:
当启动进程在 META-INF 中遇到 INDEX.LIST 时,它会信任它,并且不会去服务器上查找文件。
I solved this problem by adding an index to the JAR-file.
After building your jar, run the command:
It has to be run as a separate step from the actual JAR-ing.
Explanation:
When the startup-process encounters an INDEX.LIST in META-INF, it trusts this, and will not go looking for the files on the server.
我最近在 log4j 通过 GET 查询丢失的资源时遇到了类似的问题。在您的情况下,也许基于 Web 的类路径仍然比捆绑的 jar 具有一些优先级?
好吧,你可以尝试将所有罐子打包成一个。这当然会使构建变得复杂,但您可以手动尝试一次,看看问题是否消失。
I recently had a similar problem with log4j querying for missing resources via GETs. Maybe web-based classpath still has some priority over bundled jars in your case?
Well, you may try to pack all the jars into one. This of course complicates the build, but you may try this just once manually to see whether problem vanishes.