I would like to know what the JavaFX Image constructor's relative path resolution algorithm is for:
- Stand-alone apps.
- Browser deployed apps.
- Webstart deployed apps.
If the algorithm may look in multiple locations, I'd like to know what they are for each of the above deployment scenarios.
If the behaviour for stand-alone apps is different when the app is placed in a jar, I'd like to know that too.
The answer is "/" if case you are using
getClass().getResourceAsStream()
, i.e. the root of your jar file (inside it). Not user.dir nor where the package is hostedgetClass().getName().toString()
) related to your .java file are present, copy and paste your image thereImage image=new Image(getClass().getResourceAsStream("yourImageName.jpg"));
is must.In NetBeans the directory where classes are present NetBeansProjects/JavaFXProjectName/build/classes/packageName/
Then user provides relative path to
new Image(String url)
it will be relative against workdir of the app akaSystem.getProperty("user.dir")
javaws myfxapp.jnlp
) it works the same way as with standalone appSo general direction is: for standalone apps use
url
same way as you'll use it innew File(String url)
. For jnlp/plugin use full url with protocol orClass.getResource()
approach.Update: Please, note, this behavior is going to be clarified and changed in 2.2. See http://javafx-jira.kenai.com/browse/RT-18291
The following comment is from RT-18291 and outlines the intended changes for 2.2: