如何在 JNLP 执行期间检测函数是否可用?
我有一个确实应该安装的应用程序,但在使用 JNLP 部署时工作正常。
但是,某些 Java 函数(例如 Runtime.exec
)似乎无法使用默认安全选项运行。
因此,我想禁用依赖此类功能的UI功能。
所以我的问题是,如何在运行时检测某些函数是否可用?
这里的案例研究当然是Runtime.exec
。
I have an application which really should be installed, but does work fine when deployed using JNLP.
However, it would seem that some Java functions such as Runtime.exec
don't work using the default security options.
I would like to therefore disable UI functionality that relies upon such functions.
So my question is, how do I detect at runtime whether certain functions are available or not?
The case study, here of course, is Runtime.exec
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于 Runtime.exec 的具体示例,SecurityManager 类 checkExec(String cmd) 上有一个方法,该方法将引发异常,可以捕获该异常以确定是否可以执行必要的命令。 有关详细信息,请参阅 Runtime.exec 和 SecurityManager.checkExec 的 javadoc。
更一般的情况需要创建一个 Permission 对象来表示正在检查的任务并运行 SecurityManager 的 checkPermission 方法。
For the specific example of Runtime.exec there is a method on the SecurityManager class checkExec(String cmd) that will throw an exception that can be caught to determine if the necessary command can be executed. For more information see the javadoc for Runtime.exec and SecurityManager.checkExec.
The more general case requires creating a Permission object representing the task being checked and running SecurityManager's checkPermission method.
我还发现,将以下内容添加到 JNLP 文件中:
并对 JAR 文件进行签名允许应用程序以
Runtime.exec
所需的所有权限运行。I have also found that adding the following to the JNLP file:
And signing the JAR file allows the app to run with all the permissions needed for
Runtime.exec
.您想询问 SecurityManager 如果你有使用 checkExec 方法的 Exec 权限。
You want to ask to the SecurityManager if you have Exec right with the checkExec method.