我需要管理员权限才能在 JavaFX 中使用 System.setProperty()
方法吗?我真的很困惑阅读 documentation :
@exception SecurityException if a security manager exists and its
* <code>checkPermission</code> method doesn't allow
* setting of the specified property.
什么情况下 JVM 不允许我设置属性?
如果我的应用程序是捆绑 JavaFX 应用程序,它是否有所不同? 谢谢。
最佳答案
安全管理器与通过“管理员访问权限”定义的操作系统权限无关。
安全管理器描述here 。特别注意:
A security manager is an object that defines a security policy for an application. This policy specifies actions that are unsafe or sensitive. Any actions not allowed by the security policy cause a
SecurityException
to be thrown.
和
Typically, a web applet runs with a security manager provided by the browser or Java Web Start plugin. Other kinds of applications normally run without a security manager, unless the application itself defines one. If no security manager is present, the application has no security policy and acts without restrictions.
因此,在 Web Start 下运行的应用程序将具有一个安全管理器,该管理器允许由 JNLP 文件配置的操作(并且仅允许对签名应用程序进行提升的操作)。
除非您竭尽全力改变这一点,否则作为“普通”桌面应用程序运行的独立应用程序将不会有安全管理器,并且其操作也不会受到限制。特别是,如果没有安全管理器,那么根据您引用的文档:
@exception SecurityException if a security manager exists and its
* <code>checkPermission</code> method doesn't allow
* setting of the specified property.
不会抛出SecurityException
。
关于JavaFX System.setProperty 管理员权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44134130/