Question

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.

Was it helpful?

Solution

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

  1. For signed applets you can use your custom class loader (use UrlClassLoader) that reads classes from local jar.
  2. For unsigned applets you can upload the local jar to the server and then use it from there. I think it is not so bad: from user point of view he just "helps" the application to find where the custom jar is. What really happens is that the jar is uploaded to the server and applet reads it from there. This way can be implemented using regular HTML form with input tag of type file. Using AJAX can hide a lot of details from user.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top