RMI服务器的jar在Red Hat上运行良好但在Windows上不起作用

时间:2015-05-07 17:07:35

标签: windows maven jar rmi policy

我有一个使用Maven和onejar-maven-plugin构建的RMI服务器,这个服务器在eclipse STS和Red Hat上的jar上运行良好,但如果我尝试在我的cmd上运行jar,那么服务器RMI抛出我的下一个例外:

  

java.security.AccessControlContext.checkPermission(Unknown Source),   java.security.AccessController.checkPermission(Unknown Source),   java.lang.SecurityManager.checkPermission(Unknown Source),   java.lang.Thread.setContextClassLoader(Unknown Source),   com.simontuffs.onejar.JarClassLoader.loadClass(JarClassLoader.java:629),   java.lang.ClassLoader.loadClass(Unknown Source),   modeloconfigurador.cache.manager.rmi.InterfazRMICategoriaImpl.startRMIServer(InterfazRMICategoriaImpl.java:65),   modeloconfigurador.cache.manager.rmi.InterfazRMICategoriaImpl.setPuertoRMI(InterfazRMICategoriaImpl.java:92),   modeloconfigurador.cache.manager.impl.ServicioCacheImpl.inicializa(ServicioCacheImpl.java:168),   serviciocache.CachePrincipal $ 1.run(CachePrincipal.java:79)   java.awt.event.InvocationEvent.dispatch(Unknown Source),   java.awt.EventQueue.dispatchEventImpl(未知来源),   java.awt.EventQueue.access $ 500(未知来源),   java.awt.EventQueue $ 3.run(未知来源),   java.awt.EventQueue $ 3.run(未知来源),   java.security.AccessController.doPrivileged(Native Method),   java.security.ProtectionDomain $ 1.doIntersectionPrivilege(未知   Source),java.awt.EventQueue.dispatchEvent(Unknown Source),   java.awt.EventDispatchThread.pumpOneEventForFilters(未知来源),   java.awt.EventDispatchThread.pumpEventsForFilter(未知来源),   java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source),   java.awt.EventDispatchThread.pumpEvents(未知来源),   java.awt.EventDispatchThread.pumpEvents(未知来源),   java.awt.EventDispatchThread.run(未知来源)]

似乎java JDK上的java.policy没有权限,但确实有。

我在E上运行jar:我像管理员一样打开cmd

这里是我的代码:

RMI服务器:

private void startRMIServer() {
    try{

        log.trace("Consultando privilegios java.security.policy");
        System.setProperty("java.security.policy","java.policy");

        System.setSecurityManager(new SecurityManager());

        log.trace(new StringBuilder("Creando Registrry en el puerto ").append(puertoRMI));
        _registry = LocateRegistry.createRegistry(puertoRMI);

        _interfazRMICategoriaMC=(InterfazRMICategoria)UnicastRemoteObject.exportObject(this,puertoRMI);
        String nombreObjR="ObtenerCategorias";

        _registry.bind(nombreObjR, _interfazRMICategoriaMC);
        log.info(new StringBuilder("(RMI) Objeto Remoto colocado en Registry con el nombre ").append(nombreObjR));

    }catch(Exception e){

        log.error(new StringBuilder("podible error por permisos del security manager: ").append(Arrays.toString(e.getStackTrace())));

    }
}

这是JAVA_HOME的java.policy文件:

// Standard extensions get all permissions by default

grant codeBase "file:${{java.ext.dirs}}/*" {
        permission java.security.AllPermission;
};

// default permissions granted to all domains

grant {
        // Allows any thread to stop itself using the java.lang.Thread.stop()
        // method that takes no argument.
        // Note that this permission is granted by default only to remain
        // backwards compatible.
        // It is strongly recommended that you either remove this permission
        // from this policy file or further restrict it to code sources
        // that you specify, because Thread.stop() is potentially unsafe.
        // See the API specification of java.lang.Thread.stop() for more
        // information.
        permission java.lang.RuntimePermission "stopThread";

        // allows anyone to listen on dynamic ports
        permission java.net.SocketPermission "localhost:0", "listen";

        // permission for standard RMI registry port
        permission java.net.SocketPermission "localhost:1099", "listen";

        // "standard" properies that can be read by anyone

        permission java.util.PropertyPermission "java.version", "read";
        permission java.util.PropertyPermission "java.vendor", "read";
        permission java.util.PropertyPermission "java.vendor.url", "read";
        permission java.util.PropertyPermission "java.class.version", "read";
        permission java.util.PropertyPermission "os.name", "read";
        permission java.util.PropertyPermission "os.version", "read";
        permission java.util.PropertyPermission "os.arch", "read";
        permission java.util.PropertyPermission "file.separator", "read";
        permission java.util.PropertyPermission "path.separator", "read";
        permission java.util.PropertyPermission "line.separator", "read";

        permission java.util.PropertyPermission "java.specification.version", "read";
        permission java.util.PropertyPermission "java.specification.vendor", "read";
        permission java.util.PropertyPermission "java.specification.name", "read";

        permission java.util.PropertyPermission "java.vm.specification.version", "read";
        permission java.util.PropertyPermission "java.vm.specification.vendor", "read";
        permission java.util.PropertyPermission "java.vm.specification.name", "read";
        permission java.util.PropertyPermission "java.vm.version", "read";
        permission java.util.PropertyPermission "java.vm.vendor", "read";
        permission java.util.PropertyPermission "java.vm.name", "read";
        permission java.security.AllPermission;
};

项目有自己的java.policy文件,但对于eclise是不可见的

问题是当我尝试仅在windos上运行JAR时,在IDE eclipse中,Windows上的STS运行良好,当我在Red Hat上运行相同的JAR时运行良好(在使用中从JDK修改文件java.policy) )。

1 个答案:

答案 0 :(得分:0)

  

这是JAVA_HOME

的java.policy文件

但是你没有使用JAVA_HOME的java.polcy文件。您正在使用当前目录中的任何内容(如果有)。

使用-Djava.security.debug=access,failure运行您的应用程序,您将看到确切的权限和授予的权限,以及哪些策略文件有效。 显然它不是您帖子中的那个。