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:

<container-descriptor>
    <show-archived-real-path-enabled>true</show-archived-real-path-enabled>
</container-descriptor>

You can do this by JDeveloper IDE as shown below:

4 comments:

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

    ReplyDelete
  2. Works in Eclipse too. THANKS!

    ReplyDelete