I have a web application with a following structure:
src
+ main
+-+ java
+ resources
+ webapp
+-+ WEB-INF
+ static
The static directory is server by org.apache.catalina.servlets.DefaultServlet, otherwise it is served by the application. What I am trying to achieve, is to access the static directory from the application. However, once it is deployed on the server, the directory seems to be “lost” – I can’t access it neither in relative path (by new File()) nor in classpath (by new ClassPathResource()). I could see, that the directory is missing in the target dir, which is probably correct, but I don’t know what I can do about it.
Thanks.
Edit
- Maybe it is not clear, but directory
staticis a sibling of WEB-INF and not its child. - The static directory might contain 2 GB of images. So it is not desired that this directory should be copied every time the application is deployed (so putting it in the classpath is not probably a good idea).
- I just can’t find the behaviour of DefaultServlet, which I allow to access this directory. Does it copy all the stuff somewhere else? Or does it access it as by absolute path?
I’m pretty sure WEB-INF isn’t visible to the classpath, you’d have to put it in the webapp folder. Better yet, you probably want to look into using an mvc:resources tag.
http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html
Search mvc:resources for an explaination.
EDIT
If you place the resource in src/main/resources, they should be available to a ClassPathResource