In my Maven project, I have a xls file in src/main/resources. When I read it like this:
InputStream in = new
FileInputStream(\"src/main/resources/WBU_templ
FileInputStream will load a the file path you pass to the constructor as relative from the working directory of the Java process.
getResourceAsStream() will load a file path relative from your application's classpath.
When you use .getClass().getResource(fileName)
it considers the location of the fileName is the same location of the of the calling class.
When you use .getClass().getClassLoader().getResource(fileName)
it considers the location of the fileName is the root - in other words bin folder.
The file should be located in src/main/resources
when loading using Class loader
In short, you have to use .getClass().getClassLoader().getResource(fileName)
to load the file in your case.
I usually load files from WEB-INF like this
session.getServletContext().getResourceAsStream("/WEB-INF/WBU_template.xls")