I am trying to run a desktop application which is developed in java rmi. While I am trying to execute this application in eclipse, I am getting following error. Please any one help me thanks 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's 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();
}
-Djava.security.policy =java.policy.applet
. java.policy.applet
.Add below lines in that file.
grant
{
permission java.security.AllPermission;
};
Save it and run the application.
This will give all security permissions to your Java application.
You have installed a SecurityManager and you haven't given yourself enough permissions in your .policy file to execute your code. The exception tells you what permission is missing, but there are probably more. Run your application with -Djava.security.debug=access,failure to see what other security problems there are.
But the real question here is why the security manager? You only need it in an RMI server, from the RMI point of view, if you are using the RMI codebase feature. Otherwise you should consider deleting it.
Also you must store the result of createRegistry
somewhere where it won't be garbage-collected, e.g. in a static variable. And once you've done that, the getRegistry()
call is redundant.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With