This is the directory structure of an applet project I've created.
Project
|____classes
|____src
|____resources
- The applet is in the
src
directory. - The classes are stored in the
classes
directory. - All the images, sounds and other stuff are stored in the
resources
directory.
My problem is that when I try to load an image stored in the resources
directory into my applet (which is in the classes directory when compiled), the JVM raises an AccessControlException
. I read a lot of posts in stackoverflow about this, and now I understand why it is like this (to protect the user from accessing his files). I also read that you can write policy files to fix it or signed jars.
This is how I load my image:
Image image = getImage(getCodeBase(),"path/to/the/image/image.png");
I noticed that AccesControlException
is not raised when the image I want to load is in one of the classes
sub-directory. So I can't use ..
to access the classes
parent directory, and then the resources
directory. Is there any way I can load my images without having to put them in a classes
subdirectory and without using policy files or signed jars?