Hi, I have an applet, it worked fine, until, I decided to look at the local filesystem from inside the applet.
The exception comes from using File.list() method, used so that I can get the subdirectory names of the "images" directory, which resides in the same directory as applet on the server.
Here is the output from the Sun Java Console verifying the File.list() as the place where it has an exception
Java Plug-in 1.6.0_01 Using JRE version 1.6.0_01 Java HotSpot(TM) Client VM User home directory = C:\Documents and Settings\Colin
---------------------------------------------------- c: clear console window f: finalize objects on finalization queue g: garbage collect h: display this help message l: dump classloader list m: print memory usage o: trigger logging p: reload proxy configuration q: hide console r: reload policy configuration s: dump system and deployment properties t: dump thread list v: dump thread stack x: clear classloader cache 0-5: set trace level to <n> ----------------------------------------------------
IN CONSTRUCTOR java.security.AccessControlException: access denied (java.io.FilePermission images read) at java.security.AccessControlContext.checkPermission(Unknown Source) at java.security.AccessController.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPermission(Unknown Source) at java.lang.SecurityManager.checkRead(Unknown Source) at java.io.File.list(Unknown Source) at foto.Directory.setEndDirectory(Directory.java:75) at foto.Directory.<init>(Directory.java:25) at foto.Main.start(Main.java:57) at sun.applet.AppletPanel.run(Unknown Source) at java.lang.Thread.run(Unknown Source)
Since all I need to do is read names of directories I thought it might be possible to not use a signed applet, and just use a Policy File thing.
I read Javaranch's FAQ, and it says I can use...
So for the codeBase, I replaced it with "http://www.colin-java.co.uk/FotoCube" This is the directory where the JAR file and HTML page reside.
I'm using Eclipse, which creates a java.policy.applet file, similar to the code above, so I put the new code in, and exported it with the JAR.
But I'm still getting exactly the same exception when I run the applet in the browser.
Do I have the codeBase line correct, or is the java.policy.applet code wrong, or am I doing something else wrong?
Please can someone advise me so I can read names of subdirectories inside the applet.
So this has all file permissions, and it still doesn't work, what else can I do?? Thanks for any help.
Joined: Mar 22, 2005
If you follow the link I posted you'll see how to install the file so that the JRE knows about it. Policy files don't just get picked up by being in the same place as an applet.
Joined: Apr 11, 2005
I've read it, and I'm able to follow the instructions using policytool, but after that it doesn't make any sense. Whats the point of Eclipses' java.policy.applet file if it doesn't work?
I've looked at Approach 2 of "See the Policy File Effects", And I've managed to locate the Security Properties File at java.home\lib\security\java.security
But what is 'policy.url.n' and where is it?
Ok, I've just edited this post, I got my JAR signed, and it works! I used keytool, then jarsigner from command prompt. This overwrites the jar file, and makes it work.
Not sure if I need the policy file inside the jar now or not. But I can play around with it.
Thanks [ April 20, 2007: Message edited by: colin shuker ]
Joined: Mar 22, 2005
The policy file is not needed if the applet is signed, and not used in any case. Eclipse probably creates it to help the developer make the appropriate changes to the system policy file. The link I posted talks about how to do that, and what "policy.url.n" means.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com