Question

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);
}

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

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")

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?

Was it helpful?

Solution

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

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

customerImage = new Image(imageLink.toURI().toURL().toString(),true);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top