I’m incorporating a test applet onto a new site I’m building using Django. When I load the page with the applet locally, I receive a “class not found” error.
java.lang.ClassNotFoundException: HelloWorld
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.ClassNotFoundException: HelloWorld
Applet HTML:
<applet code="HelloWorld" archive="{{ STATIC_URL }}HelloWorld.jar" width=525 height=635>
</applet>
My site root on the development machine is set up as C:/www/django/mysite.
My Django settings are:
ABSOLUTE_PATH = lambda x: os.path.join(os.path.abspath(os.path.dirname(__file__)), x)
STATIC_ROOT = ABSOLUTE_PATH('media/')
STATIC_URL = 'media/'
The applet JAR is stored in the /media/ folder. I believe I have Django’s settings correct because if I point my browser to http://localhost:8000/media/helloworld.jar it asks me to download the java file. When I load the page with the embedded applet, however, I receive the error. I think the browser is unable to find the actual jar file, but I’m not sure. I have tried a variety of alterations (add “.class”, add package prefix, etc.) to no avail. I also opened the JAR file to make sure the class-file is present – it is.
I’ve tagged this question with java and django because I’m not sure where the issue lies. Thank you for your time!
I discovered that the {STATIC_URL} variable wasn’t being served to the template. Here are the steps I followed to get my applets working:
First, I Added template context processors to setup.py:
I Added a RequestContext to my views. This supplies the template with my variables:
Finally, I edited my url patterns to serve static files while in development mode: