Exception in thread "main" java.security.AccessControlException: access denied (java.util.PropertyPermission * read, write)

I am trying to run a desktop application that is developed in java rmi. Although I am trying to run this application in eclipse, I am getting the following error. Please help me in advance.

Exception in thread "main" java.security.AccessControlException: access denied (java.util.PropertyPermission * read,write)
    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.checkPropertiesAccess(Unknown Source)
    at java.lang.System.getProperties(Unknown Source)
    at .HeadOfficeManager.Manager.main(Manager.java:103)

Here is the code.

public static void main(String args[])
{
    Manager frame = new Manager();
    frame.setVisible(true);
    // frame.show(); old 1.4

    // Create and install a security manager
    if (System.getSecurityManager()== null)
    {
        System.setSecurityManager(new RMISecurityManager());
    }
    try
    {
        Properties prop = System.getProperties();
        String httpPath = prop.getProperty("HTTPPath");
        new ClassFileServer(80, httpPath);
    }
    catch (IOException e)
    {}

    try
    {
        java.rmi.registry.LocateRegistry.createRegistry(1099);
        System.out.println("RMI registry ready.");
    }
    catch (Exception e)
    {
        System.out.println("Exception starting RMI registry:");
        e.printStackTrace();
    }
    try
    {
        RMIHandler = new ManagerRMIHandler();

        // Bind the remote object stub in the registry
        Registry registry = LocateRegistry.getRegistry();
        registry.rebind("HeadOfficeManager", RMIHandler);

        System.err.println("Server ready");
    }
    catch (Exception e)
    {
        System.err.println("Server exception: " + e.toString());
        e.printStackTrace();
    }
+5
source share
2 answers
  • Right-click on the application in eclipse and click on launch settings.
  • Add virtual machine arguments in quality -Djava.security.policy =java.policy.applet.
  • Create a file, name it as java.policy.applet.
  • Add the lines below to this file.

    grant  
    {  
        permission java.security.AllPermission;  
    };
    
  • Save it and run the application.

This will give all security permissions for your Java application.

+10
source

SecurityManager, .policy . , , , , . -Djava.security.debug = , , .

- ? RMI, RMI, RMI. .

createRegistry -, , . . , getRegistry() .

+2

All Articles