I would like to create a separate folder for my resources in a Java project. How, in the name of God do I achieve such a simple thing ? I have been trying to get it to work for quite some time now and it starts to drive me nuts. Here is what I have tried so far:
1) I opened my Build Path Settings and added a folder to my source folders called "resources".
2) I added two folders to that folder called "font" and "img" containing images and font files.
3) I try to access those files in code like this:
getClassLoader() is said to give me an absolute path, so I take a path without the leading /:
getClass().getClassLoader().getResourceAsStream("resources/font/MyFont.otf")
which returns null. Why is file management in eclipse so infuriating ?
If you have added 'resources' folder as a source folder in the build path settings you should be able to load the fonts like below.
getClass().getClassLoader().getResourceAsStream("font/MyFont.otf")
Once you specify the 'resources' folder as a source folder eclipse included it in the root of the class path for java. So you only need the path relative to the resources folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With