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:

16 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
  3. Thanks very much. The below change works for me.

    true

    ReplyDelete
  4. It seems you are so busy in last month. The detail you shared about your work and it is really impressive that's why i am waiting for your post because i get the new ideas over here and you really write so well.
    Selenium training in Chennai

    Selenium training in Bangalore

    ReplyDelete
  5. I found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing..
    Believe me I did wrote an post about tutorials for beginners with reference of your blog. 




    Selenium training in bangalore
    Selenium training in Chennai
    Selenium training in Bangalore
    Selenium training in Pune
    Selenium Online training

    ReplyDelete
  6. Thank you so much!!!!!!!!!!!!!!!!!!

    ReplyDelete