使用 <object> 标记的 Java Applet 中的 ClassNotFoundException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/651032/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ClassNotFoundException in Java Applet using <object> tag
提问by Seb
I'm trying to embed a Java Applet using the <OBJECT> tag, which is the XHTML Strict way of doing it.
我正在尝试使用 <OBJECT> 标记嵌入 Java Applet,这是 XHTML Strict 的执行方式。
After browsing lots of sites, I tried this examplewhich seems to work pretty well:
<!--[if !IE]> Firefox and others will use outer object -->
<object classid="java:Sample2.class"
type="application/x-java-applet"
archive="Sample2.jar"
height="300" width="450" >
<!-- Konqueror browser needs the following param -->
<param name="archive" value="Sample2.jar" />
<!--<![endif]-->
<!-- MSIE (Microsoft Internet Explorer) will use inner object -->
<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
codebase="http://java.sun.com/update/1.5.0/jinstall-1_5_0-windows-i586.cab"
height="300" width="450" >
<param name="code" value="Sample2" />
<param name="archive" value="Sample2.jar" />
<strong>
This browser does not have a Java Plug-in.
<br />
<a href="http://java.sun.com/products/plugin/downloads/index.html">
Get the latest Java Plug-in here.
</a>
</strong>
</object>
<!--[if !IE]> close outer object -->
</object>
<!--<![endif]-->
I downloaded that Sample2.jar and works perfectly on localhost.
我下载了 Sample2.jar 并在本地主机上完美运行。
Now, I replaced Sample2.class for the one I need to use (ar.uba.exactas.infovis.ivides.Scatterplot.class) and using my own JAR files (archive="piccolo.jar piccolox.jar netscape.jar scatterplot.jar"):
现在,我将 Sample2.class 替换为我需要使用的那个(ar.uba.exactas.infovis.ivides.Scatterplot.class)并使用我自己的 JAR 文件(archive="piccolo.jar piccolox.jar netscape.jar scatterplot.class)。罐”):
<!--[if !IE]> Firefox and others will use outer object -->
<object
classid="java:ar.uba.exactas.infovis.ivides.Scatterplot.class"
type="application/x-java-applet"
archive="piccolo.jar piccolox.jar netscape.jar scatterplot.jar"
height="300" width="450" >
<!-- Konqueror browser needs the following param -->
<param name="archive" value="piccolo.jar piccolox.jar netscape.jar scatterplot.jar" />
<!--<![endif]-->
<!-- MSIE (Microsoft Internet Explorer) will use inner object -->
<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
codebase="http://java.sun.com/update/1.5.0/jinstall-1_5_0-windows-i586.cab"
height="300" width="450" >
<param name="code" value="ar.uba.exactas.infovis.ivides.Scatterplot" />
<param name="archive" value="piccolo.jar piccolox.jar netscape.jar scatterplot.jar" />
<strong>
This browser does not have a Java Plug-in.
<br />
<a href="http://java.sun.com/products/plugin/downloads/index.html">
Get the latest Java Plug-in here.
</a>
</strong>
</object>
<!--[if !IE]> close outer object -->
</object>
<!--<![endif]-->
After doing so, I'm gettin this log dump:
这样做之后,我开始了这个日志转储:
java.lang.ClassNotFoundException: ar.uba.exactas.infovis.ivides.Scatterplot.class
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: open HTTP connection failed:http://localhost/infovisUBA/2008-2C/tpfinal/bin/ar/uba/exactas/infovis/ivides/Scatterplot/class.class
at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.access<param name="code"
value="ar.uba.exactas.infovis.ivides.Scatterplot.class" />
<param name="archive"
value="piccolo.jar piccolox.jar netscape.jar scatterplot.jar" />
0(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 7 more
Excepción: java.lang.ClassNotFoundException: ar.uba.exactas.infovis.ivides.Scatterplot.class
The only difference I see is that I'm using a class inside a package.
我看到的唯一区别是我在包中使用了一个类。
Also, please note I did make this work using the <APPLET> tag, but I cannot make it with <OBJECT>.
另外,请注意我确实使用 <APPLET> 标签完成了这项工作,但我无法使用 <OBJECT> 完成这项工作。
Any clue?
有什么线索吗?
采纳答案by Seb
Well, this was a hard one...
嗯,这是一个艰难的...
Struggled a lot of time but finally found that the problem was Opera itself. I was using an alpha version which had this bug. Now it works great!
纠结了很久,终于发现是Opera本身的问题。我使用的是有这个错误的 alpha 版本。现在效果很好!
回答by Jon Skeet
Have you by any chance written this:
你有没有机会写这个:
<param name="code"
value="ar.uba.exactas.infovis.ivides.Scatterplot" />
<param name="archive"
value="piccolo.jar piccolox.jar netscape.jar scatterplot.jar" />
instead of:
代替:
Excepción: java.lang.ClassNotFoundException:
ar.uba.exactas.infovis.ivides.Scatterplot.class
The difference is the lack of ".class" at the end of the code value. Judging by the example, it should be at the end of the classidattribute, but not at the end of the value for the codeparam.
不同之处在于代码值末尾缺少“.class”。从示例来看,它应该在classid属性的末尾,而不是在code参数值的末尾。
That's what the stack trace suggests to me:
这就是堆栈跟踪对我的建议:
Excepción: java.lang.ClassNotFoundException:
ar.uba.exactas.infovis.ivides.Scatterplot.class
I wouldn't expect to see the ".class" at the end of the class name.
我不希望在类名的末尾看到“.class”。
回答by Eddie
If it's not what Jon Skeet suggested, then check your JAR file manifests and ensure that your main class reference doesn't end in ".class". The Exception:
如果这不是 Jon Skeet 建议的,那么检查您的 JAR 文件清单并确保您的主类引用不以“.class”结尾。例外:
Caused by: java.io.IOException:
open HTTP connection failed:
http://localhost/infovisUBA/2008-2C/tpfinal/
bin/ar/uba/exactas/infovis/ivides/Scatterplot/class.class
indicates that somehow, you're telling Java to run ar.uba.exactas.infovis.ivides.Scatterplot.classinstead of ar.uba.exactas.infovis.ivides.Scatterplot. You just have to find where this is occurring.
表明不知何故,您正在告诉 Java 运行ar.uba.exactas.infovis.ivides.Scatterplot.class而不是ar.uba.exactas.infovis.ivides.Scatterplot. 你只需要找到发生这种情况的地方。
Also notice in the middle of the Exception dump, the following complaint (wrapped by me):
还要注意在异常转储中间,以下投诉(由我包装):
classid="java:ar.uba.exactas.infovis.ivides.Scatterplot.class"
it is somehow trying to load the wrong class ... you have an extra ".class"or "/class"somewhere in your HTML. Just to try this, if you have not already tried this, replace
它以某种方式试图加载错误的类......你的 HTML 中有一个额外的".class"或"/class"某个地方。只是为了试试这个,如果你还没有试过这个,请更换
classid="java:ar.uba.exactas.infovis.ivides.Scatterplot"
with
和
##代码##Also, do you get the same Exception in both browsers?
另外,您在两种浏览器中都得到相同的异常吗?
回答by akarnokd
I'm having the same problem with my applet. It runs fine from IE, but fails with ClassNotFoundException. The error message indicates, that the Firefox java plugin tries to download the class file from the server separately, and not from the supplied jar file.
我的小程序也有同样的问题。它在 IE 上运行良好,但因 ClassNotFoundException 而失败。错误消息表明,Firefox java 插件尝试单独从服务器下载类文件,而不是从提供的 jar 文件中下载。
I found out, that in Firefox, the order of the archive and code attributes matters. My original spec was:
我发现,在 Firefox 中,存档和代码属性的顺序很重要。我原来的规格是:
applet name="XYZ" code="x.y.Applet" archive="xxx.jar" codebase="" width='100%' height='100%' mayscript="mayscript"
小程序名称="XYZ" code="xyApplet" archive="xxx.jar" codebase="" width='100%' height='100%' mayscript="mayscript"
I changed the order to:
我将顺序更改为:
applet name="XYZ" archive="xxx.jar" code="x.y.Applet" width='100%' height='100%' mayscript="mayscript"
小程序名称="XYZ" 存档="xxx.jar" 代码="xyApplet" width='100%' height='100%' mayscript="mayscript"
And it works now.
它现在有效。

