在Windows 7或Vista上的任何浏览器中,它不适用于Java 1.7.我们已经看到它在Windows XP上工作.该小程序正在Apache使用mod_proxy连接到Tomcat 6的站点中运行.
这些都是为了背景信息,因为我将问题减少到一个非常简单的未签名小程序:
package myapplet; import java.applet.Applet; import java.awt.Color; import java.awt.Graphics; public class MyApplet extends Applet { private static final long serialVersionUID = 1L; public void paint(Graphics g) { g.drawRect(0,250,100); g.setColor(Color.blue); g.drawString("Look at me,I'm a Java Applet!",10,50); } }
如果这个applet类被放入一个jar文件中,另外一个jar文件的大小(压缩大小)大约为18KB,那么applet在本地运行的Tomcat 6(或Apache 2.2)服务时不加载.
我通过添加文本文件到jar文件和更改文本文件的大小来玩.通过在文本文件中添加一个字符,我得到了它从工作到不工作的点.
看着带有跟踪的控制台日志挂在正在尝试下载jar文件的位置.这是我认为挂的线程:
"thread applet-com.bright.assetbank.clientsideedit.myapplet.MyApplet-1" prio=4 tid=0x048d8c00 nid=0x19b8 runnable [0x0700d000] java.lang.Thread.State: RUNNABLE at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(Unknown Source) at java.net.SocketInputStream.read(Unknown Source) at java.io.BufferedInputStream.read1(Unknown Source) at java.io.BufferedInputStream.read(Unknown Source) - locked <0x29fd75b0> (a java.io.BufferedInputStream) at sun.net.www.MeteredStream.read(Unknown Source) - locked <0x29fd75d0> (a sun.net.www.http.KeepAliveStream) at java.io.FilterInputStream.read(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(Unknown Source) at java.io.BufferedInputStream.read1(Unknown Source) at java.io.BufferedInputStream.read(Unknown Source) - locked <0x29fd7630> (a java.io.BufferedInputStream) at java.io.FilterInputStream.read(Unknown Source) at sun.plugin.PluginURLJarFileCallBack.downloadJAR(Unknown Source) at sun.plugin.PluginURLJarFileCallBack.access$000(Unknown Source) at sun.plugin.PluginURLJarFileCallBack$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at sun.plugin.PluginURLJarFileCallBack.retrieve(Unknown Source) at sun.net.www.protocol.jar.URLJarFile.retrieve(Unknown Source) at sun.net.www.protocol.jar.URLJarFile.getJarFile(Unknown Source) at sun.net.www.protocol.jar.JarFileFactory.get(Unknown Source) at sun.net.www.protocol.jar.JarURLConnection.connect(Unknown Source) at sun.plugin.net.protocol.jar.CachedJarURLConnection.connect(Unknown Source) at sun.plugin.net.protocol.jar.CachedJarURLConnection.getJarFileInternal(Unknown Source) - locked <0x29f2a938> (a sun.plugin.net.protocol.jar.CachedJarURLConnection) at sun.plugin.net.protocol.jar.CachedJarURLConnection.getJarFile(Unknown Source) - locked <0x29f2a938> (a sun.plugin.net.protocol.jar.CachedJarURLConnection) at com.sun.deploy.security.DeployURLClassPath$JarLoader.getJarFile(Unknown Source) at com.sun.deploy.security.DeployURLClassPath$JarLoader.access$1000(Unknown Source) at com.sun.deploy.security.DeployURLClassPath$JarLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at com.sun.deploy.security.DeployURLClassPath$JarLoader.ensureOpen(Unknown Source) at com.sun.deploy.security.DeployURLClassPath$JarLoader.<init>(Unknown Source) at com.sun.deploy.security.DeployURLClassPath$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at com.sun.deploy.security.DeployURLClassPath.getLoader(Unknown Source) at com.sun.deploy.security.DeployURLClassPath.getLoader(Unknown Source) - locked <0x29dc7e98> (a com.sun.deploy.security.DeployURLClassPath) at com.sun.deploy.security.DeployURLClassPath.getResource(Unknown Source) at sun.plugin2.applet.Plugin2ClassLoader$2.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at sun.plugin2.applet.Plugin2ClassLoader.findClassHelper(Unknown Source) at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source) at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source) at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source) - locked <0x29dc7ed8> (a sun.plugin2.applet.Applet2ClassLoader) at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source) at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source) - locked <0x29dc7f78> (a sun.plugin2.applet.Applet2ClassLoader) at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source) - locked <0x29dc7f78> (a sun.plugin2.applet.Applet2ClassLoader) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source) at sun.plugin2.applet.Plugin2Manager.initAppletAdapter(Unknown Source) at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source) at java.lang.Thread.run(Unknown Source)
以下是Java控制台中的最后4行:
network: Cache entry not found [url: http://localhost/editor.jar,version: null] network: Connecting http://localhost/editor.jar with proxy=DIRECT network: Connecting http://localhost:80/ with proxy=DIRECT network: Connecting http://localhost/editor.jar with cookie "csrftoken=523154b2e73a76b6f2088464bd4df4f7"
一些额外的信息:
>在浏览器中运行Java 7的Windows Vista中,如果我取消选中“启用黑名单撤销检查”,则会加载我们的主applet(由Apache-> mod_proxy-> tomcat提供).如果这样做,它不会加载.取消选中此功能在Windows 7上没有任何效果(即不使其正常工作).
>我尝试在Tomcat(本地),Apache(本地)和Apache(在通过Internet访问的远程服务器)上托管我的测试小程序.对于每一个都有一个大小的jar文件,小程序不会加载到该文件,但是这个大小在Web服务器之间是不同的.例如,在远程服务器上,jar文件可能会更大 – 在加载之前它必须超过1MB.
有没有人看到这种行为,当试图加载一个applet与Java 7运行在Windows 7或Vista上的浏览器?有解决方案吗?
分步说明如何重现此问题:
>将上面的代码复制到一个名为MyApplet.java的文件中
目录叫做myapplet
>编译代码,即javac MyApplet.java
>创建一个jar文件:cd到myapplet的父目录并键入jar -cvf editor.jar myapplet
>创建一个简单的HTML页面来显示小程序.
例如:
<html> <body> <applet code="myapplet.MyApplet" name="MyApplet" width="300" height="300" archive= "editor.jar" ></applet> </body> </html>
将此HTML文件和jar文件放入同一个目录,并从Web服务器提供服务器. Apache或Tomcat.
>在Windows 7操作系统上的Chrome或IE浏览此HTML页面.小程序会加载好!
>重复上述步骤,但这次放一个小文件,例如在创建jar文件之前,将图像(例如< 2KB)放入myapplet目录(MyApplet.class旁边).这也应该起作用.
>重复,但是在创建jar文件之前,这个时候会将一个大的图像(例如> 100KB)放入myapplet目录(MyApplet.class旁边).这个jar文件现在会很大.这将不起作用,即小程序不会加载.如果是这样,而您正在使用Windows 7,那么请让我知道.在测试时,不要忘记applet被缓存,所以按下java控制台中的x键来刷新类加载器缓存和f5刷新浏览器.
-Djava.net.preferIPv4Stack=true
到JVM参数.
例如,要让我的测试applet运行(参见我上面的例子):
<html> <body> <applet code="myapplet.MyApplet" name="MyApplet" width="300" height="300" archive= "editor.jar" > <param name="java_arguments" value="-Djava.net.preferIPv4Stack=true"> </applet> </body> </html>
这可能是因为托管我们的小程序的远程服务器目前不允许IPv6通过其防火墙通信.
有趣的是,当运行Java 1.7_05时,我们的一些Windows 7机器仍然无法使用此解决方法,但是当升级到Java 1.7_06(现在可用)时,此工作正在运行(有此解决方法).