Is it possible to have an Applet use a local jar?
My Applet application needs to have some dependencies ( 66Mb worth of jars). The user can install the jars previously, but how can I use them from the applet?
I can have them saved to default locations c:/myApp and /usr/local/myApp
I tried loading them with:
ClassLoader loader = URLClassLoader.newInstance(
new URL[]{new URL("file://" + path + "/xuggle-xuggler-5.2.jar")},
JNLP2Manager.getCurrentManager().getAppletClassLoader()
);
Thread.currentThread().setContextClassLoader(loader);
But the jar does not get automatically added to classpath, I mean, I still have to load each class individually.
Doing the following works:
Class cls = loader.loadClass("com.xuggle.xuggler.video.ConverterFactory");
String testString = ConverterFactory.XUGGLER_ARGB_32;
But can I have all the classes added to the applet loader?
P.S. I know I shouldn't be using Applet , but Applet is still the best fit for my kind of application.
No, it is impossible directly at least for unsigned applets. The applet classpath is defined relatively to its codebase that is typically where applet is downloaded from.
Here are possible workarounds
UrlClassLoader
) that reads classes from local jar. file
. Using AJAX can hide a lot of details from user.