安全策略文件和jar

编程入门 行业动态 更新时间:2024-10-26 08:26:50
本文介绍了安全策略文件和jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有RMI应用程序,所以我需要使用策略文件。

I have got RMI application, so I need to use policy files.

我的政策文件很简单(conf.txt):

my policy file is simple (conf.txt):

grant { permission java.security.AllPermission; };

从eclipse运行我的应用程序没有问题。我已经添加了:-Djava.security.policy = conf.txt到VM参数。

I have no problems running my application from eclipse. I've added: -Djava.security.policy=conf.txt to the VM arguments.

我想要做的是构建一个jar文件。我把它作为来自eclipse的Runnable JAR文件,我在运行它时遇到了一些问题。我尝试像这样运行它:

What I want to do is to build a jar file. I made it as Runnable JAR file from eclipse and I'm having some problems running it. I try to run it like this:

java -Djava.security.policy=C:\Users\myuser\proj\conf.txt -jar C:\Users\myuser\proj\proj.jar

我得到与没有-Djava.security.policy选项相同的结果。

I get the same result as without -Djava.security.policy option.

我的代码:

System.setProperty("java.security.policy", "./conf.txt"); ... if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); }

如何才能使这个工作?如果我不必传递-Djava.security.policy就更好了:

How can I make this working? It would be even better if I don't have to pass -Djava.security.policy just:

java -jar myprog.jar

推荐答案

首先,删除您的代码中的System.setProperty(java.security.policy,。/ conf.txt); 。它覆盖了您在命令行中设置的值,并且其中包含完整路径并且可以工作。在任何情况下,如果代码中有 System.setProperty ,则不会测试该命令行的效果。

For starters, remove System.setProperty("java.security.policy", "./conf.txt"); from you code. Its overriding the value you set at the command line, and that one had the full path in it and could have worked. In any case you are not testing the effect of that command line if you have System.setProperty in the code.

更多推荐

安全策略文件和jar

本文发布于:2023-08-01 15:41:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1269569.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:安全策略   文件   jar

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!