如何将VM选项添加到jar文件中?
我需要添加 -Djava.security.policy=myPolicyFile
以便我的 RMI jar 能够工作。或者还有其他方法可以运行吗?
I need to add -Djava.security.policy=myPolicyFile
so that my RMI jar would work. Or is there some other way to make that run?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想在有人使用
java -jar
启动您的 jar 时添加 -D,这是不可能的,因为无法在 jar 内指定 JVM 选项:我可以设置从 jar 文件运行的 Java 最大堆大小吗?
也就是说,如果您控制该过程,则可以使用 java.security.Policy.setPolicy 自己管理策略对象。
If you're wanting to add the -D when someone launches your jar using
java -jar
, that's not possible because it's not possible to specify JVM options inside the jar:Can I set Java max heap size for running from a jar file?
That said, if you're in control of the process, you could use
java.security.Policy.setPolicy
to manage the policy object yourself.您可以在此处查看如何使用策略文件。如果您使用 netbeans 或其他一些 IDE,您应该能够添加
作为虚拟机的一个选项,通常可以在项目属性中的某个位置找到。
You can take a look here on how to use policy files. If you are using netbeans or some other IDE, you should be able to add
as an option to your VM, which is usually found somewhere within the project's properties.