我正在尝试运行一个用 java rmi 开发的桌面应用程序。当我尝试在 Eclipse 中执行此应用程序时,出现以下错误。请任何人帮助我提前致谢。
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)
这是代码。
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();
}
最佳答案
- 右键单击 eclipse 中的应用程序,然后单击运行配置。
- 将虚拟机参数添加为
-Djava.security.policy =java.policy.applet
。 - 创建一个文件,将其命名为
java.policy.applet
。 在该文件中添加以下行。
grant { permission java.security.AllPermission; };
保存并运行应用程序。
这将为您的 Java 应用程序授予所有安全权限。
关于java - 线程 "main"java.security.AccessControlException : access denied (java. util.PropertyPermission * 读、写中的异常),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10978343/