Applet类装载器不能找到在applet的jar类 [英] Applet class loader cannot find a class in the applet's jar

查看:1097
本文介绍了Applet类装载器不能找到在applet的jar类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始问这个问题,然后提交前想出答案。我决定无论如何要发布问题,这样谁遇到同样的问题,其他人就可以从我的错误中学习。


我在与一个小程序有问题(一的 JApplet的实际上)无法实例包括在同一个瓶子的小程序的类。我看到在Java控制台的例外是:


异常螺纹线程applet的com.company.program.cm.hmi.MediatorApplet-1java.lang.NoClassDefFoundError的:COM /公司/程序/厘米/ CS / JDataStore的
    在com.company.program.cm.hmi.MediatorApplet.getMediator(MediatorApplet.java:63)
    在com.company.program.cm.hmi.MediatorApplet.init(MediatorApplet.java:49)
    在sun.plugin2.applet.Plugin2Manager $ AppletExecutionRunnable.run(来源不明)
    在java.lang.Thread.run(来源不明)
抛出java.lang.ClassNotFoundException:引起com.company.program.cm.cs.JDataStore
    在sun.plugin2.applet.Applet2ClassLoader.findClass(来源不明)
    在java.lang.ClassLoader.loadClass(来源不明)
    在java.lang.ClassLoader.loadClass(来源不明)
    在java.lang.ClassLoader.loadClassInternal(来源不明)
    ... 4个
java.io.IOException异常:引起开放的HTTP连接失败:HTTP://本地主机:8080 / TransportHMI /页/ COM /公司/程序/厘米/ CS / JDataStore.class
    在sun.plugin2.applet.Applet2ClassLoader.getBytes(来源不明)
    在sun.plugin2.applet.Applet2ClassLoader.access $ 000(来源不明)
    在sun.plugin2.applet.Applet2ClassLoader $ 1.run(来源不明)
    在java.security.AccessController.doPrivileged(本机方法)
    ... 8个

我知道 JDataStore的类包含在瓶子里。如果我列出使用罐子TVF CM_Library.jar内容我可以看到,它是有正确的包下。然而,上述铅我链式例外相信类加载器未搜索 JDataStore的档案,并寻找Web服务器上的JDataStore.class文件,而不是。为什么是这样?类加载器就会知道从罐子里载入MediatorApplet类,为什么没有检查它的JDataStore的呢?如果我没有指定正确的applet标记的参数,我会包括在这里也:

 <小程序ID =调解员的小程序
        宽度=0
        高度=0
        codeBase的=./
        归档=CM_Library.jar
        code =com.company.program.cm.hmi.MediatorApplet>
< /小程序>


解决方案

找到了答案,从看的 发布的<一个建议href=\"http://stackoverflow.com/questions/698890/applet-fails-to-load-class-from-jar/699031#699031\">related问题。埃迪的答案并没有解决这个特定的问题,但它确实给我我的解决方案。

什么是不是从我的问题特别明显的是,JDataStore的类从它包含在一个不同的罐子另一个类继承。我还没有处理JDataStore的在几个月的实施细则,所以我完全忘记了它的父类,org.json.simple.JSONObject,是不是在CM_Library.jar,但在json_simple-1.0 .2.jar。该修复程序相当简单,只是缺少罐子复制到codeBase的目录和丢失的jar添加到在applet标记的归档属性档案的逗号分隔列表

 &LT;小程序ID =调解员的小程序
        宽度=0
        高度=0
        codeBase的=./
        归档=CM_Library.jar,json_simple-1.0.2.jar
        code =com.company.program.cm.hmi.MediatorApplet&GT;
&LT; /小程序&GT;

这是修正错误。异常消息是不是特别有帮助。这将导致您认为它无法找到类可言,当实际问题是,它无法加载超类的请求的类。

I started to ask this question and then figured out the answer before submitting it. I've decided to post the question anyway so that other people who run into the same problem will be able to learn from my mistakes.


I'm having a problem with an applet (a JApplet actually) unable to instantiate another class which is included in the same jar as the applet. The exception I'm seeing on the Java console is:

Exception in thread "thread applet-com.company.program.cm.hmi.MediatorApplet-1" java.lang.NoClassDefFoundError: com/company/program/cm/cs/JDataStore
    at com.company.program.cm.hmi.MediatorApplet.getMediator(MediatorApplet.java:63)
    at com.company.program.cm.hmi.MediatorApplet.init(MediatorApplet.java:49)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.company.program.cm.cs.JDataStore
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    ... 4 more
Caused by: java.io.IOException: open HTTP connection failed:http://localhost:8080/TransportHMI/pages/com/company/program/cm/cs/JDataStore.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)
    ... 8 more

I know that the JDataStore class is included in the jar. If I list the contents using jar tvf CM_Library.jar I can see that it is there under the proper package. However, the chained exceptions above lead me to believe that the class loader isn't searching the archive for JDataStore, and is looking for the JDataStore.class file on the web server instead. Why is this? The class loader knows to load the MediatorApplet class from the jar, why doesn't it check it for JDataStore as well? In case I haven't specified the parameters correctly on the applet tag, I'll include that here as well:

<applet id="mediator-applet"
        width="0"
        height="0"
        codebase="./"
        archive="CM_Library.jar"
        code="com.company.program.cm.hmi.MediatorApplet">
</applet>

解决方案

Found the answer from looking at a suggestion posted for a related question. Eddie's answer didn't solve that particular problem, but it did give me the solution for mine.

What isn't particularly obvious from my question is that the JDataStore class inherits from another class which is contained in a different jar. I hadn't had to deal with the implementation details of JDataStore in a couple of months, so I completely forgot that its parent class, org.json.simple.JSONObject, wasn't in CM_Library.jar, but was in json_simple-1.0.2.jar. The fix is fairly simple, just copy the missing jar to the codebase directory and add the missing jar to the comma-separated list of archives in the applet tag's archive attribute:

<applet id="mediator-applet"
        width="0"
        height="0"
        codebase="./"
        archive="CM_Library.jar, json_simple-1.0.2.jar"
        code="com.company.program.cm.hmi.MediatorApplet">
</applet>

That fixes the error. The exception message is not particularly helpful. It would lead you to believe that it can't find the class at all, when the actual problem is that it cannot load the super class for the requested class.

这篇关于Applet类装载器不能找到在applet的jar类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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