Search code examples
eclipsewebsphere-libertyopen-liberty

getServletContext().getRealPath("") returning null in WebSphere Application Server Liberty


I was previously using Tomcat v9.0 in local environment, while using

getServletContext().getRealPath("")

to retrieve the path, server returned

....metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\WebApp\

However as client runs WebSphere Application Server Liberty i installed the same on my machine, but the same code that returns a path in Tomcat, returns

null

in Websphere environment. Could you help me understands as to why this happens and how will I get the path in Websphere environment. Also I have checked the following link https://www.ibm.com/developerworks/community/forums/html/topic?id=eb04c8ae-02d4-421b-af2c-2ef626a3db1b&ps=50&tags=&query=&filter=&sortBy=&order=asc, yet couldn't find a solution.


Solution

  • I did get the path in the Websphere environment. In Websphere, it is required that we have to give a '/' instead of empty string i.e

    getServletContext().getRealPath("/")

    instead of

    getServletContext().getRealPath("")

    I am not sure if it holds true for all the cases, but it worked fine in my machine.