我在jar文件中存档了许多类。我已加载到服务器上的唯一东西是.jar文件。有许多.class文件,但是具有init()方法的文件称为“ Poker.class”。我的html如下:

<applet code=Poker
    archive="Poker.jar"
    width=300
    height=300>
</applet>


我试图用“ Poker.class”,“ Poker.class”和“ Poker”替换applet代码。当我加载网页时,这些变体在Java控制台上会给出稍微不同的错误消息,其中的区别只是它找不到的类名。错误消息复制到下面。

我搜索了试图找到答案的网站,但没有任何帮助。如果您有任何见解,将不胜感激。谢谢

Java Plug-in 1.6.0_22
Using JRE version 1.6.0_22-b04 Java HotSpot(TM) Client VM
User home directory = C:\Users\Matt
----------------------------------------------------
c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
l:   dump classloader list
m:   print memory usage
o:   trigger logging
q:   hide console
r:   reload policy configuration
s:   dump system and deployment properties
t:   dump thread list
v:   dump thread stack
x:   clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
load: class Poker not found.
java.lang.ClassNotFoundException: Poker
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.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:https://files.nyu.edu/mbn247/public/Poker.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)
    ... 9 more
Exception: java.lang.ClassNotFoundException: Poker

最佳答案

啊,我终于找到答案了。对于那些可能处于同样困境的人:

您必须在代码参数中指定包名称。因此,我的程序包称为“ poker”,类为“ Poker.class”,我的html应该如下所示:

<applet code="poker.Poker.class"
    archive="Poker.jar"
    width=300
    height=300>
</applet>

09-27 17:14