title: java policy permissions under osx appletviewer
body: <p>I made a java game that saves the high score in a file, but I am having trouble giving the program enough permissions for it to work under appletviewer.</p>
  
  <p>It seems that appletviewer is ignoring my policy file.</p>
  
  <p>I have <code>Game.java</code> compiled into <code>Game.class</code>, and <code>Game.html</code> loads and runs the applet.  In the same directory as these, I have a policy file named <code>policy</code> with the following contents (made with <code>policytool</code>).</p>
  
  <pre><code>grant codeBase "file:///mypath/Game.html" {
    permission java.security.AllPermission;
  };
  </code></pre>
  
  <p>Then <code>appletviewer</code> supposedly lets you specify a policy file like this:</p>
  
  <pre><code>appletviewer -J-Djava.security.policy=policy /mypath/Game.html
  </code></pre>
  
  <p>But when I start the game this way, it can only read the highscore file, not write to it:</p>
  
  <pre><code>Exception in thread "Thread-5" java.security.AccessControlException:
                          access denied (java.io.FilePermission highscore write)
  </code></pre>
  
  <p>Furthermore, if I double-click in the Finder on a shell script containing just the one-line appletviewer command above, then it doesn't even have read permission:</p>
  
  <pre><code>Exception in thread "Thread-5" java.security.AccessControlException:
                          access denied (java.io.FilePermission highscore read)
  </code></pre>
  
  <p>One troubling sign is that if I give the name of a non-existent file instead of my policy file, then I get the same behavior, with no additional warnings or errors:</p>
  
  <pre><code>appletviewer -J-Djava.security.policy=notafile /mypath/Game.html
  </code></pre>
  
  <p>The game itself (apart from the high-score code) works fine in every case, and the high-score code is also working fine if I run the whole thing under Eclipse, even though Eclipse also runs it using appletviewer.  Eclipse also makes a policy file much like the above one, which I also tried from the command line, but it still didn't work from the command line.</p>
  
  <p>It seems that <code>appletviewer</code> is not looking at the policy file, although I am using the command exactly as shown in various tutorials such as <a href="http://docs.oracle.com/javase/tutorial/security/tour1/step3.html" rel="nofollow">http://docs.oracle.com/javase/tutorial/security/tour1/step3.html</a>.</p>
  
  <p>Why does appletviewer ignore my policy file?</p>