Reputation: 12416
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
static
is a sibling of WEB-INF and not its child.Upvotes: 2
Views: 2880
Reputation: 10136
There is no standardized way to access files stored under WEB-INF. The spirit of the WEB-INF folder is that it contains data that the framework (container/server) reads. It is not seen as a place for data that the user of the container (you) read directly. Depending on the container software (and version) that you are using (Tomcat vs. JBoss vs. WebSphere vs. WebLogic, etc), you might be able to kludge your way into WEB-INF, but it would not be portable across containers, and so I would not recommend it.
Consider putting the files somewhere else, such as in the classpath or in a subfolder of the webapp that is not WEB-INF.
Upvotes: 1
Reputation: 4970
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
Upvotes: 2