java - 使用 <object> 标记的 Java Applet 中的 ClassNotFoundException

标签 java xhtml applet

我正在尝试使用 标记嵌入 Java Applet,这是执行此操作的 XHTML Strict 方法。

浏览了很多网站后,我尝试了this example这似乎工作得很好:

<!--[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]-->

我下载了 Sample2.jar 并且在本地主机上完美运行。

现在,我将 Sample2.class 替换为我需要使用的 (ar.uba.exactas.infovis.ivides.Scatterplot.class) 并使用我自己的 JAR 文件 (archive="piccolo.jar piccolox.jar netscape.jar scatterplot.jar"):

<!--[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]-->

这样做之后,我得到了这个日志转储:

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$000(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    ... 7 more
Excepción: java.lang.ClassNotFoundException: ar.uba.exactas.infovis.ivides.Scatterplot.class

我看到的唯一区别是我在包中使用了一个类。

另外,请注意,我确实使用 标记完成了这项工作,但我无法使用 完成这项工作。

有什么线索吗?

最佳答案

您是否有机会写过这样的内容:

<param name="code" 
       value="ar.uba.exactas.infovis.ivides.Scatterplot.class" />
<param name="archive"
       value="piccolo.jar piccolox.jar netscape.jar scatterplot.jar" />

而不是:

<param name="code"
       value="ar.uba.exactas.infovis.ivides.Scatterplot" />
<param name="archive"
       value="piccolo.jar piccolox.jar netscape.jar scatterplot.jar" />

区别在于代码值末尾缺少“.class”。从示例来看,它应该位于 classid 属性的末尾,而不是位于 code 参数值的末尾。

这就是堆栈跟踪向我建议的内容:

Excepción: java.lang.ClassNotFoundException: 
    ar.uba.exactas.infovis.ivides.Scatterplot.class

我不希望在类名末尾看到“.class”。

关于java - 使用 <object> 标记的 Java Applet 中的 ClassNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/651032/