users@jersey.java.net

Getting ServletContext or real path on filesystem

From: Rene Wiermer <r.wiermer_at_lw-systems.de>
Date: Fri, 01 Aug 2008 14:43:51 +0200

I am using Spring to read a configuration from WEB-INF.

In my normal servlet this works fine:

  BeanFactory factory =
new XmlBeanFactory(new
ServletContextResource(servletContextProvidedByServlet,
"WEB-INF/applicationContext-config.xml"));

Here servletContextProvidedByServlet.getRealPath("/") points to
"/real/fspath/to/webapp"

However, in my REST service in the same application using Jersey, the
ServletContext is filled differently

Using:

@Context private ServletContext servletContextInjectedByJersey;

This ist not loaded correctly by the ServletContextResource. (I/O
error).

Reason: servletContextInjectedByJersey.getRealPath("/") gives "/webapp"

Question: is there some way to get the real path from a Resource, or is
there another way to access files in WEB-INF ?

Thanks in advance,
Rene Wiermer