多次获取 Java 小程序依赖项 [英] Java applet dependencies fetched multiple times

查看:17
本文介绍了多次获取 Java 小程序依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Web 应用程序我目前正在研究嵌入 ,它有几个依赖项(.jar 文件).

Web application I'm currently investigating embeds <applet>, which has several dependencies (.jar files).

Applet 标记如下所示:

Applet tag looks like that:

<applet ...
        type="application/x-java-applet"
        codebase="/webapp/applet">
     ...
     <param name="codebase" value="./applet"/>
     <param name="archive" value="a.jar,b.jar,c.jar"/>
     <param name="codebase_lookup" value="false"/>
</applet>

Applet 工作正常,但问题是,当它第一次加载时,那些 a.jar、b.jar、c.jar 等正在被请求(并下载)从 Web 服务器多次(20-300)次,每次都会使小程序启动速度很慢.

Applet works OK, but the problem is, that when it loads for the first time, those a.jar, b.jar, c.jar, etc. are being requested (and downloaded) from web server MANY (20-300) times, each, which makes applet start-up quite slow.

这是怎么回事,是否为每个加载的类分别重新下载了 jars?

Whats going on, are jars being re-downloaded for each loaded class separately?

有没有办法正确优化/配置小程序?尝试了几种缓存技巧(比如 <param name="cache_archive"/> ,但没有成功,甚至不确定这是解决这个问题的正确方法.

Is there a way to optimize/configure applet properly? Tried several caching tricks (like <param name="cache_archive" /> , but no success and not even sure it's right way to approach this problem.

注意!这个小程序是WS 客户端(有一些JAXB 注释的类和相关的依赖项).

NB! this applet is WS client (has some JAXB-annotated classes and related dependencies).

Applet 登录启动有很多:

Applet log on start-up has plenty of those:

network: Connecting http://127.0.0.1:7001/webapp/applet/a.jar with proxy=DIRECT
network: Connecting http://127.0.0.1:7001/webapp/applet/a.jar with proxy=DIRECT
network: Connecting http://127.0.0.1:7001/webapp/applet/a.jar with proxy=DIRECT
... ~100 more times a.jar is downloaded
network: Connecting http://127.0.0.1:7001/webapp/applet/a.jar with proxy=DIRECT
network: Connecting http://127.0.0.1:7001/webapp/applet/b.jar with proxy=DIRECT
network: Connecting http://127.0.0.1:7001/webapp/applet/b.jar with proxy=DIRECT
network: Connecting http://127.0.0.1:7001/webapp/applet/c.jar with proxy=DIRECT
network: Connecting http://127.0.0.1:7001/webapp/applet/a.jar with proxy=DIRECT
network: Connecting http://127.0.0.1:7001/webapp/applet/c.jar with proxy=DIRECT
...

Web 服务器访问日志反映小程序日志:

Web server access log reflects applet log:

127.0.0.1 - "GET /webapp/applet/a.jar HTTP/1.1" 200 1232582 
127.0.0.1 - "GET /webapp/applet/a.jar HTTP/1.1" 200 1232582 
127.0.0.1 - "GET /webapp/applet/a.jar HTTP/1.1" 200 1232582 
...
127.0.0.1 - "GET /webapp/applet/a.jar HTTP/1.1" 200 1232582 

推荐答案

发生这种情况是因为在 CXFURL.openStream() 用于从 jars 访问不同的资源(架构、wsdls 等).

This was happening because in CXF URL.openStream() was used to access different resources from jars (schemas, wsdls, etc).

问题已通过将 URL.openStream() 替换为 classloader 中的 getResourceAsStream() 方法(显然是 Applet2ClassLoader.getResource().openStream() 进行不必要的连接,而 Applet2ClassLoader.getResourceAsStream() 不会.

Issue was solved by replacing URL.openStream() with getResourceAsStream() method from classloader (apparently Applet2ClassLoader.getResource().openStream() makes unnecessary connection and Applet2ClassLoader.getResourceAsStream() does not).

更新:它似乎在 Java7 插件上工作,但不是 Java6 插件.

Update: it seems to be working on Java7 Plugin, but not Java6 one.

这篇关于多次获取 Java 小程序依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆