0

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?

CarrKnight
  • 2,768
  • 2
  • 23
  • 25

1 Answers1

2
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);
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • the problem with this is that I need to deal with URL malformation exception which is a pain in a static initialization. JavaFX guide says to use class-loader's getResourceAsStream() which is a bit less annoying – CarrKnight Apr 15 '14 at 14:27