Friday, November 4, 2011

How to fix: Weblogic ServletContext.getRealPath() returns null

Weblogic Server[WLS] returns null if your code is using Servlet.getRealPath(). You can suppose that it's another weblogic server bug but it's not.

The problem is the way in which you deploy the application. If the application was deployed in exploded mode, getRealPath returns occured, valid value. But, if you deploy it as an archive having extentions like war, ear etc.  you will see "null pointer" Exception. Fortunatelly there is simple way to avoid this exception. You can fix this problem in domain level, setting weblogic Admin Console option Domain | Web Application | Archived Real Path Enabled to true, as shown below:

You can also apply fix in application level by adding the following entry to weblogic.xml file:


You can do this by JDeveloper IDE as shown below:


  1. Muchas Gracias, me sirvió mucho, llevaba un par de días tratando de dar con el error!!!

  2. Works in Eclipse too. THANKS!

  3. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java EE Online Training from India . Nowadays Java has tons of job opportunities on various vertical industry.