as already stated this won't work for an OSGi Servlet Container. 
All of the deployment together with those information are handled by Pax Web. 
Jetty is just the mere container to run the stuff. 

To retrieve the actual ServletPath you will need to call request.getServletPath()

But, this will not solve your problem. You need to be aware that since you are running in Karaf
some things do work different here. So an access to the deployment directory is not possible. 
Since there is no such deployment directory. 
So for your exact use-case one possibility would be to use an extracted war in the deploy folder, which isn't nice
but could work. 
From an OSGi perspective I'd suggest using a fragment bundle for your configuration file, that is why the fragment bundle have been invented for, and attach this to your WAB. 
Another possibility, use the configuration admin Service for the custom configuration, with this solution you'll need to alter your
wab a bit though, to get a hold of the configuration. 

regards, Achim 

2014-03-06 1:12 GMT+01:00 asookazian2 <asookazian@gmail.com>:
I found the following Jetty bug report:

User states the following:

"ServletContext.getRealPath("") returns null instead of returning the root
dir of the webapp"

I am able to reproduce this behavior in my WAR bundle with MANIFEST.MF (WAB
(WebApplication Bundle)) deployment to Karaf 3.0.0.  The version of Jetty is
the following:

karaf@root()> feature:list | grep jetty
cxf-http-jetty                | 3.0.0-milestone2 | x         |
cxf-3.0.0-milestone2    |
jetty                         | 8.1.9.v20130131  | x         |
standard-3.0.0          |
pax-jetty                     | 8.1.14.v20131031 | x         |
org.ops4j.pax.web-3.0.5 | Provide Jetty engine support

I have tried ServletContext.getRealPath("");

I have also tried ServletContext.getRealPath("/");

Both code lines return null.

Is this expected for this version of Karaf/Jetty?  If yes, how can I
determine the real path.

Our scenario involves a properties file that may be installed in
karaf/config/foo directory.  We don't want to load/read the file from inside
the WAR (e.g. WEB-INF) b/c the customer may need to change the file.

View this message in context: http://karaf.922171.n3.nabble.com/unable-to-getRealPath-for-servlet-context-tp4032109.html
Sent from the Karaf - User mailing list archive at Nabble.com.


Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer & Project Lead
blog <http://notizblog.nierbeck.de/>

Software Architect / Project Manager / Scrum Master