Applet 类加载器找不到 jar 中的类之一

发布于 2024-08-23 03:22:54 字数 1953 浏览 11 评论 0原文

我明白了。 Java 控制台偶尔会出现错误:

Exception in thread "thread applet-my.package.MyApplet-10" java.lang.NoClassDefFoundError: another/package/SomeClass
    at my.package.MyApplet.init(MyApplet.java:95)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: another.package.SomeClass
    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)
    ... 3 more
Caused by: java.io.IOException: open HTTP connection failed:https://myserver/mycontext/applets/another/package/SomeClass.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

我的小程序标签如下:

<applet codebase="../../applets" code="my.package.MyApplet" class="invisible" id="myApplet">
  <param value="value0" name="param0"/>
  ...
  <param value="valueN" name="paramN" />
  <param value="folder/myApplet__0.0.1177.jar,folder/commons-io-1.3.2__0.0.1177.jar,..." name="cache_archive"/>
  <param value="0.0.1177.0,0.0.1177.0,...," name="cache_version"/>
</applet>

我强调“偶尔”这个词很重要。有时小程序会顺利初始化。这也意味着,通常,当浏览器重新启动时,问题就会消失。

我知道 小程序无法从 jar 加载类Applet 类加载器无法在 applet 的 jar 中找到类< /a> 但我认为它们不适用于我的情况。 SomeClass 和 MyApplet 位于同一个 jar 中,并且正在本地访问该页面。

I get the ff. error in Java Console occassionally:

Exception in thread "thread applet-my.package.MyApplet-10" java.lang.NoClassDefFoundError: another/package/SomeClass
    at my.package.MyApplet.init(MyApplet.java:95)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: another.package.SomeClass
    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)
    ... 3 more
Caused by: java.io.IOException: open HTTP connection failed:https://myserver/mycontext/applets/another/package/SomeClass.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

My applet tag is as follows:

<applet codebase="../../applets" code="my.package.MyApplet" class="invisible" id="myApplet">
  <param value="value0" name="param0"/>
  ...
  <param value="valueN" name="paramN" />
  <param value="folder/myApplet__0.0.1177.jar,folder/commons-io-1.3.2__0.0.1177.jar,..." name="cache_archive"/>
  <param value="0.0.1177.0,0.0.1177.0,...," name="cache_version"/>
</applet>

It is important I stress the word "occasionally". Sometimes the applet is initialized without a hitch. This also means that, often, when the browser is restarted, the problem goes away.

I am aware of applet fails to load class from jar and Applet class loader cannot find a class in the applet's jar but I think they are not applicable to my case. SomeClass and MyApplet are in the same jar and the page is being accessed locally.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生生不灭 2024-08-30 03:22:54
Caused by: java.io.IOException: open HTTP connection failed:https://myserver/mycontext/applets/another/package/SomeClass.class

从 HTTPS 服务器检索 jar 文件时似乎存在连接问题。

我不知道您运行的 Java 版本到底是什么,但您可以检查与您的问题相关的缺陷原因 此处

如果这不是问题,请确保下载 JAR 文件时有足够的缓存,否则它将无法启动。不幸的是,这不是代码问题。

更新您的类SomeClass是否有机会访问任何远程服务器或数据库?

该异常清楚地表明存在已被拒绝的 AccessControl 权限。

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)

请记住,小程序就像 Flash 对象:

  • 它们都是从客户端下载和运行的。

唯一的区别是,Applet 设计有很多访问控制规则,例如,它不能连接到隐藏在公司 DMZ(非军事区)后面的服务器等。

如果是这种情况,我建议您找到一种方法来检索您的数据外部小程序(尝试 servlet?)

更新 2 看来 JVM 找不到与您签名的 jar 匹配的可信证书。

  1. 由于您的 jar 文件已签名,请确保该 jar 文件可以指向您的受信任证书(请记住,它必须是受信任的)。
  2. 更多信息,请检查: http://faq.javaranch.com/java/HowCanAnAppletReadFilesOnTheLocalFileSystem 和 < a href="http://www.developer.com/article.php/3303561" rel="nofollow noreferrer">http://www.developer.com/article.php/3303561
Caused by: java.io.IOException: open HTTP connection failed:https://myserver/mycontext/applets/another/package/SomeClass.class

This looks like there is a connection issue with retrieving the jar file from the HTTPS server.

I don't know exactly what version of Java are you running, but you can check the reason of the defect pertaining to your problem here.

If this is not the problem, then make sure that there's enough caching for your JAR file when downloaded else it fails to launch. It's not code issue unfortunately.

UPDATE Is your class SomeClass accessing any remote server or database by any chance?

The exception clearly shows that there is an AccessControl privilege that has been denied.

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)

Bear in mind, that applets are like Flash Objects:

  • They are both downloaded and run from the client side.

Only difference is that Applets were designed with lots of access control rules such as, it must not connect to servers hidden behind company DMZ (De-Militarized Zone), etc.

If that's the case, I suggest you find a way to retrieve your data outside applets (try servlet?)

UPDATE 2 It seems the JVM can't find the trusted certificate to match with your signed jar.

  1. Since your jar file is signed make sure that the jar file can point your trusted certificate (remember, it must be trusted).
  2. More information, check: http://faq.javaranch.com/java/HowCanAnAppletReadFilesOnTheLocalFileSystem AND http://www.developer.com/article.php/3303561
七禾 2024-08-30 03:22:54

可能与 http://download.oracle 有关.com/javase/6/docs/api/java/util/ServiceLoader.html。即,一个或多个罐子定义/期望一个提供者。有时间就去调查一下。

Probably has something to do with http://download.oracle.com/javase/6/docs/api/java/util/ServiceLoader.html. I.e., one or more of the jars defines/expects a provider. Investigate when there is time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文