Java Applet 部署、ClassNotFoundException(初级类)

发布于 2024-09-05 05:13:37 字数 2335 浏览 3 评论 0原文

这让我陷入困境。我已经检查并重新检查了拼写和路径。我尝试了几乎所有路径组合,包括相对路径、绝对路径和完整 http 路径。尝试加载 Java 小程序时,我继续收到以下错误:

java.lang.ClassNotFoundException: AppletClient.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)
Exception: java.lang.ClassNotFoundException: AppletClient.class

用于加载小程序的 HTML:

<applet width="100" height="100" archive="applet/myapplet.jar, applet/applet_dependency.jar" code="AppletClient.class">
    <param value="blahblah" name="username">
    <param value="false" name="codebase_lookup">
</applet>

小程序位于当前页面路径的相对目录“小程序”中。我已经解压了 jar 文件,可以看到 AppletClient.class。另外,在项目的源代码中,它是这样拼写的(外壳和所有)。我尝试过带/不带参数。我更改了小程序包含标记中存档 jar 的名称,只是为了看看是否会因错误文件名而收到不同的错误(相同的错误)。

我已经在 jar 上手动完成了 GET,以确保服务器正在响应请求(确实如此)。

我尝试过使用和不使用代码库标签,以及所有不同种类的路径(开始在这些路径上出现严重的“幻数”错误)。

我知道,当依赖项无法加载时,有时会弹出此错误,因此它可能会产生误导,但所有依赖项都存在、已说明,并且可以通过手动 GET 获取。

在每次尝试之间,我总是清除 FireFox 中的缓存。这些问题在 IE8 和 Chrome 中也重现。

根据浏览器中的 Java 控制台,我正在运行 Java 插件 1.6.0_20。这是来自我开发小程序的同一台机器,它通过 Eclipse 运行良好。

最后,我启动了 Fiddler2,并且在任何地方都没有看到对 jar 文件的单个请求 主机站点是从我的 Visual Studio 调试器运行的,因此它在本地主机上运行。但我在 Fiddler 上看到了对所有其他资源的请求。只是...没有罐子。任何地方。我清除了日志,清除了浏览器缓存,并执行了 ctrl-R 刷新。而且 Fiddler 日志上仍然没有任何 Jar 请求。

一旦所有 Fiddler 活动减慢,我什至在页面加载后对小程序标记进行了延迟写入(使用 JS)。该元素被写入文档(我可以看到 100x100 Java 错误窗口),但 Fiddler 上没有显示单个请求。

在我爬到角落里哭着入睡之前,有什么建议吗?

编辑:从Java控制台,如果我点击“l”(el)到“转储类加载器列表”,我会看到如下所示的内容:

Live entry: key=http://localhost:55446/BaseWebSite/,http://localhost:55446/BaseWebSite/applet/myappliet.jar, http://localhost:55446/BaseWebSite/applet/applet_dependency.jar, refCount=1, threadGroup=sun.plugin2.applet.Applet2ThreadGroup[name=http://localhost:55446/BaseWebSite/-threadGroup,maxpri=4]

编辑2:小程序做了一些网络(Jabber/XMPP),所以我做了一个自我- 签署证书以查看是否有帮助。收到有关自签名证书的提示 - 所以它正在读取某些内容 - 但仍然不起作用。而且它没有出现在Java缓存文件列表中......并且Fiddler上仍然没有任何内容。

This is driving me up the wall. I have checked and rechecked spelling and paths. I have tried just about every combination of paths, including relative, absolute, and full http paths. I continue to get the following error when trying to load a Java applet:

java.lang.ClassNotFoundException: AppletClient.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)
Exception: java.lang.ClassNotFoundException: AppletClient.class

The HTML used to load the applet:

<applet width="100" height="100" archive="applet/myapplet.jar, applet/applet_dependency.jar" code="AppletClient.class">
    <param value="blahblah" name="username">
    <param value="false" name="codebase_lookup">
</applet>

The applet is in a relative directory, "applet", from the path of the current page. I have unzipped the jar file and can see AppletClient.class. Also, in the source of the project, it is spelled that way (casing and all). I have tried with/without the parameters. I have changed the names of the archive jars in the applet include tag just to see if I get a different error for bad file names (same error).

I have manually done GETs on the jars to make sure the server is responding to the requests (it is).

I have tried with and without the codebase tag, with all different varieties of paths (start getting bad "magic number" errors on those).

I know that this error sometimes pops up when a dependency fails to load, so it can be misleading, but all dependencies are present, accounted for, and are fetchable via manual GETs.

Between each and every attempt I always clear my cache in FireFox. These problems are reproduced in IE8 and Chrome as well.

Per my Java Console from the browser, I am running Java Plug-in 1.6.0_20. This is from the same machine that I develop the applet on, which runs fine via Eclipse.

Finally, I kicked on Fiddler2, and I don't see a single request for the jar files anywhere The host site is running from my Visual Studio debugger, so it's running on localhost. But I see the requests for all the other resources on Fiddler. Just... no Jars. ANYWHERE. I clear the log, cleared my browser cache, and did a ctrl-R refresh. And still, not a single Jar request on the Fiddler log.

I even did a delayed write (with JS) of the applet tag after the page loaded, once all the Fiddler activity slowed down. The element gets written to the document (and I can see the 100x100 Java error window), but not a single request shows up on Fiddler.

Any suggestions, before I go crawl into the corner and cry myself to sleep?

EDIT: From the Java console, if I hit "l" (el) to "dump classloader list", I see something that looks like this:

Live entry: key=http://localhost:55446/BaseWebSite/,http://localhost:55446/BaseWebSite/applet/myappliet.jar, http://localhost:55446/BaseWebSite/applet/applet_dependency.jar, refCount=1, threadGroup=sun.plugin2.applet.Applet2ThreadGroup[name=http://localhost:55446/BaseWebSite/-threadGroup,maxpri=4]

EDIT 2: The applet does some networking (Jabber/XMPP), so I did a self-signed cert to see if that helped. Get prompted regarding the self signed cert - so it's reading something - but still doesn't work. And it is not showing up in the Java cache file list... and still nothing on Fiddler.

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

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

发布评论

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

评论(2

情话难免假 2024-09-12 05:13:39

我认为 Java 插件有自己的缓存,您可能想尝试清空。我运行的是 Windows,我在控制面板中找到它。在常规选项卡中,有一个“Internet 临时文件”部分,看看您是否可以在那里找到一些东西?

在设置对话框中,我可以看到硬盘上缓存的 .jar 的位置,并且有几次我不得不手动删除它。

另外,请确保通过在控制台中按 x 清除类加载器缓存。

只是为了确定,AppletClient 是否确实位于默认类路径中,即不在包中?如果没有,您需要在标记中引用限定的类名 (code="your.package.AppletClient")。

更新:

此时没有具体的建议,除非您已经有,否则您可以做的是尝试另一种标记样式,看看是否有任何变化。这是我用过的东西:

<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width="380" height="260">
    <param name="code" value="AppletClient" />
    <param name="archive" value="applet/myapplet.jar,applet/applet_dependency.jar" />
    <comment>
        <embed
            code="AppletClient.class"
            type="application/x-java-applet;version=1.6"
            archive="applet/myapplet.jar,applet/applet_dependency.jar"
            width="380"
            height="260">
            <noembed>No Java Support.</noembed>
        </embed>
     </comment>
</object>

I think the Java Plugin has its own cache you might want to try and empty. I'm running Windows, I find it in my control panel. In the general tab, there's a Temporary Internet Files section, see if you can find something there?

In the settings dialog, I can see the location of the cached .jars on my hard drive, and I've had to nuke it manually on a few occasions.

Also, make sure to clear the classloader cache by pressing x in the console.

Just to make sure, is AppletClient really in the default classpath, i.e. not in a package? If not, you would need to reference the qualified class name in your markup (code="your.package.AppletClient").

UPDATE:

Out of specific suggestions at this point, what you could do unless you already have is to try another markup style and just see if anything changes. Here's something I've used:

<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width="380" height="260">
    <param name="code" value="AppletClient" />
    <param name="archive" value="applet/myapplet.jar,applet/applet_dependency.jar" />
    <comment>
        <embed
            code="AppletClient.class"
            type="application/x-java-applet;version=1.6"
            archive="applet/myapplet.jar,applet/applet_dependency.jar"
            width="380"
            height="260">
            <noembed>No Java Support.</noembed>
        </embed>
     </comment>
</object>
星軌x 2024-09-12 05:13:39

事实证明我的问题实际上是多个问题的组合。我会暂时解决一个问题,但由于这不起作用(因为还有其他问题),我会返回并尝试另一种方法。

我在这里尝试了很多不同的方法,以至于我不确定确切的修复是什么。但是,我认为归根结底是

1)由于我的小程序使用网络组件(Jabber/XMPP),因此需要对其进行签名。

2) 尽管在测试的早期我确认 jar 文件是以正确的方式打包的,Applet.class 位于根目录,但后来在调试中我创建了一个 NAnt 构建脚本来简化构建/签名/部署对我来说过程。此构建脚本从工作目录打包 jar,该工作目录不是应用程序的根目录。因此,AppletClient.class 不再位于根目录,而是嵌套在多个子目录中。

It turns out my problem was actually a combination of problems. I would temporarily solve one, but since that didn't work (since there were other problems), I would revert back and try another approach.

I've tried so many different things here that I'm not sure what the exact fix was. But, I think what it boiled down to was

1) Since my applet uses networking components (Jabber/XMPP), it needed to be signed.

2) Even though early on in my testing I confirmed that the jar file was packaged in the correct fashion, with the Applet.class at the root, later on in my debugging I created a NAnt build script for simplifying the build/sign/deploy process for me. This build script was packaging the jar from a working directory that was not the root of the application. So, the AppletClient.class was not at the root anymore, but nested in sever subdirectories.

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