Loading applet with custom class loader


My problem is a little complicated. I'll try to explain in details - but pls do not hesitate and ask for clarifications...

I have a product - applet based. I want to manipulate the code on run-time using aspectj. Since the applet is running on the client jvm I can't load it with '-Djava.system.class.loader=org.aspectj.weaver.loadtime.WeavingURLClassLoader' as with applications.

My current solution is to 'replace' the applet tag in the jsp - to call a wrapper applet. The wrapper applet is initiate the product with the aspectj classloader:

            URL source = new URL("jar:"+getCodeBase()+"aProduct.jar!/");

            URL aspect = new URL("jar:"+getCodeBase()+"myAspects.jar!/");

            URL[] urlList = {source, aspect };

            URL[] aspectsList = {aspect };

            WeavingURLClassLoader weavingClassLoader = new WeavingURLClassLoader(urlList, aspectsList,         



            Class mainApplet = weavingClassLoader.loadClass("com.company.product.ProductApplet");

            Object applet = mainApplet.newInstance();      

            if (mainApplet != null) {           

                Class[] stubArgs = {AppletStub.class};

                Method setStub = mainApplet.getMethod("setStub", stubArgs);

                Object[] stubObjects = {new MyAppletStub(this)};

                setStub.invoke(applet, stubObjects);

                Class[] args = null;

                Method init = mainApplet.getMethod("init", args);

                init.invoke(applet, (Object[])null);



The product applet is trying to get info from the browser and to interact with java script - but it lost its 'connection' to the browser when I loaded it and add it to the wrapper applet. This is why I'm setting the applet stub - so whenever someone is calling 'getParameter', getJSObject or getAppletContext - it's getting my wrapper 'getParameter', getJSObject or getAppletContext. - this is working great!

the current status is that the product is having some controllers for the GUI that have one instance for each applet on the browser (there are cases that some applets are running on the same page). The product is using:

JOptionPane.getFrameForComponent(component)   - (where the component is the applet)

in order to select between the controllers.

I'm running in debug mode and getting the same controller for the product applet - but in some cases (still for the same applet) I'm getting another controller (it trys to get the parent frame - that is my wrapper applet frame) - this is causing eventually to a null pointer.

Since we have a decision - not to touch the product code and to be generic to all products - I need to find a way to solve this out.

another option is trying the 'new java plugin' - 6. they added an option to load applet using jnlp (as in webstart). You can load the applet with jvm arguments. But I'm not sure that loading it with:


will pass the security restrictions

Any thought/suggestion  will be more then welcome

Thank you for your interest!

We will contact you as soon as possible.

Want to Know More?

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com
Thank you for your interest!

We will contact you as soon as possible.

Let's talk

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com