如何将两个 applet Jars 加载到非 applet gui 程序?
我正在尝试找到一种方法将两个 Jars(TestApplet.jar 和 Shared.jar)正确加载到 swing gui 中。我已经成功加载 TestApplet.jar 但它给出了 NoClassDefFoundError 异常,因为我还没有找到如何加载 Shared.jar 。
这是页面上的 HTML 代码:
<applet id="testapplet" class="topspacer" codebase="http://codebase.url.com/applets/" code="TestApplet" archive="TestApplet.jar,/Shared/Shared.jar" width="645" height="465">
<param name="initmessage" value="Initializing..." />
<!-- ... Other parameters ... -->
这是我启动 TestApplet 的方式:
ClassLoader clientClassLoader = new URLClassLoader(new URL[]{new URL("http://codebase.url.com/applets/TestApplet.jar")});
Applet loader = (Applet) clientClassLoader.loadClass("TestApplet").asSubclass(Applet.class).newInstance();
loader.init();
loader.start();
那么基本上,我如何正确加载 Shared.jar 供 TestApplet 使用? 只需询问您是否需要更多详细信息或一些说明。
编辑:错误是这样的:线程“main”java.lang.NoClassDefFoundError中的异常:com/shared/singleclient/SingleGame
I'm trying to find a way to correctly load both of the Jars (TestApplet.jar and Shared.jar) to a swing gui. I already succeeded to load TestApplet.jar but it gives NoClassDefFoundError exception because I haven't found out how to load Shared.jar too.
This is the HTML code on page:
<applet id="testapplet" class="topspacer" codebase="http://codebase.url.com/applets/" code="TestApplet" archive="TestApplet.jar,/Shared/Shared.jar" width="645" height="465">
<param name="initmessage" value="Initializing..." />
<!-- ... Other parameters ... -->
This is how I start the TestApplet:
ClassLoader clientClassLoader = new URLClassLoader(new URL[]{new URL("http://codebase.url.com/applets/TestApplet.jar")});
Applet loader = (Applet) clientClassLoader.loadClass("TestApplet").asSubclass(Applet.class).newInstance();
loader.init();
loader.start();
So basically, how do I correctly load the Shared.jar for TestApplet's use?
Just ask if you need more details or some clarification.
EDIT: And the error is this: Exception in thread "main" java.lang.NoClassDefFoundError: com/shared/singleclient/SingleGame
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过将 Shared.jar 添加到
URLClassLoader
中的 URL 集中?像这样的事情:或者,您可以确保父
ClassLoader
可以找到 Shared.jar,尽管将其包含在URLClassLoader
中会更接近正常环境小程序。Have you tried adding Shared.jar to the set of URLs in your
URLClassLoader
? Something like this:Alternatively, you could make sure that Shared.jar can be found by the parent
ClassLoader
, though including it in theURLClassLoader
would more closely approximate the normal environment for applets.