java - 线程 "main"java.security.AccessControlException : access denied (java. util.PropertyPermission * 读、写中的异常)

标签 java exception

我正在尝试运行一个用 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();
    }

最佳答案

  1. 右键单击 eclipse 中的应用程序,然后单击运行配置。
  2. 将虚拟机参数添加为 -Djava.security.policy =java.policy.applet
  3. 创建一个文件,将其命名为java.policy.applet
  4. 在该文件中添加以下行。

    grant  
    {  
        permission java.security.AllPermission;  
    };
    
  5. 保存并运行应用程序。

这将为您的 Java 应用程序授予所有安全权限。

关于java - 线程 "main"java.security.AccessControlException : access denied (java. util.PropertyPermission * 读、写中的异常),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10978343/

相关文章:

java - 标记不会改变

java - JcaPEMKeyConverter 由可选依赖项 BouncyCaSTLe 提供。要使用对 EC key 的支持,您必须显式添加对类路径的依赖

java - 自定义 JSP 标记中的 session

c# - 在 C# 中缓存异常实例是一种好习惯吗

python - 异常传播到函数调用链的多远?

java - 将多个git存储库导入Intellij中的一个项目

java - 你怎么知道一个方法可以抛出的所有异常

.net - 如何从在 TFS 2010 上运行的测试结果中获取内部异常文本

java - checked exception/unchecked exception应该什么时候选?

c# - WCF 超时太快 & 'Connection was closed unexpectedly' 异常