I am currently writing a JavaFX application and am having trouble correctly configuring the resources. My project, "Project", has a source structure as follows:
Here the resources directory is marked as a resource directory, while the java directory is marked as the sources directory.
I have a .css file in src/main/java/rootPackageName/view/styling.css . This file refers to some images in the resources directory. Using IDEA's autocomplete suggests the path "../../../resources/button.png" for the image file, giving a css entry as below.
While this is technically correct, refering to the image file using a relative path like this does not seem to work properly in IDEA. The image files are copied from resources into out/production/*.png , but java looks for the resources in
I believe this is because the path is relative, so from /out/production/rootPackageName/view/ it refers to out/ where it needs to refer to out/production/rootPackageName/resources.
I can avoid this problem if I refer to the images absolutely, e.g.:
However this has multiple drawback as first, I cannot use IDEA autocomplete to fill in these suggestions, not to mention that intelliJ gives "cannot resolve directory" error when using this format. The program compiles and runs fine, but it is hugely annoying. There must be a simple solution to this, but I am really at a loss here.
So, some questions arise:
1) Why does IDEA copy the files from src/main/resources/ into /out/ and not out/production/resources/ ?
2) How can I refer to my image using a directory structure relative to the root of the project, and not relative to the css source file?
3) Alternative, how can I prevent IDEA from giving me so many errors when refering to the absolute path.