在javafx中加载图像会导致AccessControlException部署为JNLP时
-
21-12-2019 - |
题
我有一个非常简单的javafx应用程序。它需要绘制一个图像,我将作为PNG保存在“资源”目录中。 我初始化它:
private final static Image customerImage;
static {
Path imageLink = Paths.get("resources", "homeIcon.png");
customerImage = new Image("file:"+imageLink.toString(),true);
}
.
当我直接从IDE运行时,这正常。
但是当我将应用程序部署为javafx包并运行生成的jnlp时,映像构造函数抛出AccessControlException,具体:
java.security.AccessControlException: access denied ("java.util.PropertyPermission" "user.dir" "read")
.
如果我正确理解,这意味着它无法访问搜索文件。我该如何解决这个问题?它看起来似乎很奇怪,它会在部署为.jnpl时看目录,我应该将.png文件放在其他地方吗?
解决方案
customerImage = new Image("file:"+imageLink.toString(),true);
.
可能没有形成URL。 它应该是:
customerImage = new Image(imageLink.toURI().toURL().toString(),true);
. 不隶属于 StackOverflow