4

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.

Andy Guibert
  • 41,446
  • 8
  • 38
  • 61

1 Answers1

5

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.

  • Yes, in addition you will need expanded war, so either set the `` if you just put applications in the `dropin` folder, or expand the war in the `apps` folder and add them to the `server.xml`. It will not work if the app will be kept in the packed form as archive. – Gas Sep 26 '17 at 16:32