部署为jnlp时,在JavaFX中加载图像会导致AccessControlException [英] Loading image in JavaFX causes AccessControlException when deployed as jnlp

查看:68
本文介绍了部署为jnlp时,在JavaFX中加载图像会导致AccessControlException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的JavaFX应用程序.它需要在资​​源"目录中绘制我以png形式保存的图像. 我这样初始化它:

I have a very simple JavaFX application. It needs to draw an image I keep as a png in the "resources" directory. I initialize it like this:

private final static Image customerImage;
static {
    Path imageLink = Paths.get("resources", "homeIcon.png");
    customerImage = new Image("file:"+imageLink.toString(),true);
}

当我直接从IDE中运行它时,它可以很好地工作.

This works fine when I run it straight from my IDE.

但是,当我将应用程序部署为JavaFX包并运行生成的jnlp时,Image构造函数将抛出AccessControlException,具体是:

But when I deploy the application as a JavaFX package and run the resulting jnlp then the Image constructor throws an AccessControlException, specifically:

java.security.AccessControlException: access denied ("java.util.PropertyPermission" "user.dir" "read")

如果我理解正确,则表示它无权搜索文件.我该如何解决?当部署为.jnpl时,它会出现在目录中似乎也很奇怪,我是否应该将.png文件放置在其他位置?

Which, if I understand correctly, means it doesn't have access to search for the file. How should I resolve this? It also seems strange that it would look in a directory when deployed as .jnpl, should I place the .png file somewhere else?

推荐答案

customerImage = new Image("file:"+imageLink.toString(),true);

这可能不是URL. 应该是:

That is probably not forming an URL. It should be:

customerImage = new Image(imageLink.toURI().toURL().toString(),true);

这篇关于部署为jnlp时,在JavaFX中加载图像会导致AccessControlException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆