user3241544
user3241544

Reputation: 61

How To Edit Java Policy File?

I am having a problem using netbeans in which im trying to start the Java DB. Its giving me an access denied error. After some research i have found this Unable to start derby database from Netbeans 7.4 which provides a fix. I attempted to edit the java policy file but I am unable to open the java.policy file because I am unsure how. I have also found this, which says how to open the poicy file http://docs.oracle.com/javase/tutorial/security/tour2/wstep1.html but when I enter policy tool at command line, nothing pops up.

This is the error i keep recieving

Mon Jan 27 13:09:48 EST 2014 : Security manager installed using the Basic server security policy.
Mon Jan 27 13:09:48 EST 2014 : access denied ("java.net.SocketPermission" "localhost:1527" "listen,resolve")
java.security.AccessControlException: access denied ("java.net.SocketPermission" "localhost:1527" "listen,resolve")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:372)
    at java.security.AccessController.checkPermission(AccessController.java:559)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
    at java.lang.SecurityManager.checkListen(SecurityManager.java:1134)
    at java.net.ServerSocket.bind(ServerSocket.java:375)
    at java.net.ServerSocket.<init>(ServerSocket.java:237)
    at javax.net.DefaultServerSocketFactory.createServerSocket(ServerSocketFactory.java:231)
    at org.apache.derby.impl.drda.NetworkServerControlImpl.createServerSocket(Unknown Source)
    at org.apache.derby.impl.drda.NetworkServerControlImpl.access$000(Unknown Source)
    at org.apache.derby.impl.drda.NetworkServerControlImpl$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.apache.derby.impl.drda.NetworkServerControlImpl.blockingStart(Unknown Source)
    at org.apache.derby.impl.drda.NetworkServerControlImpl.executeWork(Unknown Source)
    at org.apache.derby.drda.NetworkServerControl.main(Unknown Source)

Upvotes: 3

Views: 10122

Answers (2)

openrory
openrory

Reputation: 71

I'm on a Mac (running OSX Mavericks, JDK 1.7 update 51, and Glassfish 4.0) and I had the same problem being unable to edit the file. So I did the following:

  1. Find your java.policy file in /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/security/
  2. start VIM by typing sudo vim java.policy
  3. Go into file insert mode by typing the Vim command a
  4. add the following code to your permissions: // permission for Glassfish 4.0 deployment permission java.net.SocketPermission "localhost:1527", "listen";
  5. go back to the command mode by pressing the Esc button.
  6. Now save and quit the file by typing :wq
  7. Restart the server and you should be okay

Upvotes: 1

lorinpa
lorinpa

Reputation: 556

Make sure you back up the policy file before attempting to edit :)

The policy file is just a text file. You would edit like you would a java source file (I.E. with a text editor). Remember, make a backup of the file first (play it safe).

Hope that helps:)

Upvotes: 0

Related Questions