Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse source folder not recognized

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 ?

like image 856
the_critic Avatar asked Jan 02 '26 00:01

the_critic


1 Answers

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.

like image 192
Dev Blanked Avatar answered Jan 03 '26 13:01

Dev Blanked



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!