I’m trying to build a large Java project by building many small, modular projects. I want each small project to be entirely self contained, holding all of its resources (such as images).
I am using Eclipse. If I configure the build path to add one of the modular projects, the resource references don’t work. The system cannot find the file specified. The same thing occurs if I export a jar and include that in the libraries tab of configure build path.
I’ve done some experimenting, and haven’t been able to figure out a way to get it to work. I’ve tried using source folders for resources and using:
// this works if resource is located in package alongside class file,
// not where I want it
getClass().getResourceAsStream("resource.abc")
or
new FileInputStream("path/to/resource.abc")
Maybe I’m missing something about how projects are structured. I’ve always been able to get resources to work from a single project within the IDE without any trouble. What is different when you start linking multiple projects or including them as jars?
My ideal structure would be to have another folder, at the same level as the src folder in the root of my project, that would contain all of my resources, separate from source code. This is how it was set up before all the trouble trying to link projects/jars.
This solution worked for me:
My package structure looked like this:
References: