I've a Java application which depends upon local source binaries, such as fonts and images. Whilst developing in Eclispe, I made use of a /res
directory within my /src
to house these dependencies, resulting in an example project structure would look like this:
- src
- res
lena.png
- com.foo
Main.java
Within Main.java, the following invocation could be used to acquire a resource reference.
final File lFile = new File(Main.class.getClassLoader().getResource("res/lena.png")).getPath());
This approach has served me well throughout my development, but since moving to IntelliJ it results in a FileNotFoundException
. This is the only aspect of the application that has ceased to function since the transition.
Do dependencies need to be registered in a different manner than simply inserting them into the project structure when using IntelliJ? Is there an IDE-independent approach that I should be using instead?
Here's the Exception
; it looks like it's pointing towards the compiled directory (/bin
) but I could be mistaken:
java.io.FileNotFoundException: /home/alexander/Development/application-1/application/bin/res/fonts/lena.png (No such file or directory)
I modified the Project from using Inherit Project Compile Output Path to use Compile to Module Output Path, which changed the output directory from Eclipse's /bin
to IntelliJ's /out
. The runtime path updated accordingly. I still fail to access the files, though I can confirm they exist within the /out
hierarchy, and they point to the correct location.