Hello!
In a web application running in a local tomcat, I am trying to load a folder /folder
which is in tomcat/webapps/myproject/WEB-INF/folder
To do it:
InputStream realPath = getClass().getClassLoader().getResourceAsStream("/folder");
Which returns null
. This piece of code is supposed to load resources from classpath, which is if I am not wrong in the path where my folder is in.
Anyway, I moved my folder to different paths, such as tomcat/webapps/myproject/WEB-INF/classes/folder
or tomcat/webapps/myproject/WEB-INF/lib/folder
with the same result.
Did I miss something? Thanks in advance.
Regarding on all your answers (thanks), I edit my question with all I have tryed, with the same null result.
A)
String realSource = getServletContext().getRealPath("/folder");
B)
InputStream realPath = getClass().getClassLoader().getResourceAsStream("/folder/fileInFolder");
C)
ServletContext servletContext = (ServletContext)context.getExternalContext().getContext();
String realSource = servletContext.getRealPath("/folder");
I must say that my folder
path is tomcat/webapps/myproject/WEB-INF/classes/folder