I have JavaFX project which I build with gradle 6.3. The directory structure is as follows:
src:
--main:
----java:
------my/package:
--------controller
--------model
--------view
--------MainApplication.java
----resources:
------my/package:
--------CSS
--------FXML
--------icons
In MainApplication.java I get the correct path, getClass().getResource("")
returns path/to/project/folder/DLSimulator/build/resources/main/psopv/group9/
. But if I query the resource path from another subdirectory like 'view' I get the path to the source of 'view' and not the path to the resources folder. So for example, if I call getClass().getResource("")
from a class within the 'view' subdirectory, I get path/to/project/folder/DLSimulator/build/classes/java/main/psopv/group9/view/
which obviously causes getClass().getModule().getResourceAsStream("/icons/delete.png")
to return null because there is no icons folder in the location where the 'view' subdirectory (or subpackage) is located.
Is this the correct behaviour, or should the returned path for the resources from within view/ be the same as within MainApplication.java? If so how can I correct this, so I get the correct path to the resource folder from whichever subdirectory I call the getResource()
function?