If I'm running a signed Java applet. Can I load additional classes from remote sources, in the same domain or maybe even the same host, and run them?
I'd like to do this without changing pages or even stopping the current applet. Of course, the total size of all classes is too large to load them all at once.
Is there a way to do this? And is there a way to do this with signed applets and preserve their "confidence" status?
I think classes are lazy loaded in applets. being loaded on demand.
Anyway, if the classes are outside of a jar you can simply use the applet classloader and load them by name. Ex:
ClassLoader loader = this.getClass().getClassLoader();
Class clazz = loader.loadClass("acme.AppletAddon");
If you want to load classes from a jar I think you will need to create a new instance of URLClassLoader with the url(s) of the jar(s).
URL[] urls = new URL[]{new URL("http://localhost:8080/addon.jar")};
URLClassLoader loader = URLClassLoader.newInstance(urls,this.getClass().getClassLoader());
Class clazz = loader.loadClass("acme.AppletAddon");
By default, applets are forbidden to create new classloaders. But if you sign your applet and include permission to create new classloaders you can do it.