I'm trying to find a way to corr开发者_C百科ectly 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
Have you tried adding Shared.jar to the set of URLs in your URLClassLoader
? Something like this:
ClassLoader clientClassLoader = new URLClassLoader(new URL[]{
new URL("http://codebase.url.com/applets/TestApplet.jar"),
new URL("http://codebase.url.com/applets/Shared.jar")
});
Alternatively, you could make sure that Shared.jar can be found by the parent ClassLoader
, though including it in the URLClassLoader
would more closely approximate the normal environment for applets.
精彩评论