• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

getServletContext().getRealPath("WEB-INF/classes") returns null from EAR file in WebLogic 9.2

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to get the real path of a file in WebLogic 9.2. When I do this via an enterprise application it gives the real path. Whereas, when I do it via an EAR file then it returns null. I also found out that this is a security feature introduced by WebLogic 9.2. I also tried using a configuration tag in weblogic-application.xml but it didn't work. Please let me know if there is a work around for this.


Thanks,
-Pranav
 
Bartender
Posts: 9625
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the JavaRanch.
Why do you need to path to the classes directory? If you are trying to read some file, use Class.getResource() or Class.getResourceAsStream().
 
Pranav Thakur
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

That was just a sample code. There is a word doc for which I need the exact path. I tried it out with this and it worked:

getServletContext().getResource("/resources/CONFERENCE_EMAIL_ATTACHMENT_FILE).getPath().substring(1)

Do let me know if there's another work around for this.

Thanks anyways
 
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

this is stated in specification. getRealpath() method is supposed to return null from packaged applications.



This method returns null if the servlet container cannot translate the virtual path to a real path for any reason (such as when the content is being made available from a .war archive).



Javadocs also say that:

http://java.sun.com/products/servlet/2.5/docs/servlet-2_5-mr2/index.html

take a look at ServletContext.getRealPath() in docs above.


You should consider mapping a directory if you need access to static resources. If you're loading some properties or configuration files(xml) you should NOT use getRealPath to find it.

[]s
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try console-->server-->Protocols-->HTTP
√ Accept Context Path In Get Real Path (Select this item)
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This gave me nightmares. I don't know why weblogic behaves differently when deployed as WAR instead of exploded. There are 2 ways to fix this - domain level and webapp level. please visit this blog entry for the same.

http://ananthkannan.blogspot.com/2009/12/servletcontextgetrealpath-returns-null.html

Hope this helps.
Andy
 
Marcos Maia
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Andy Kay wrote:This gave me nightmares. I don't know why weblogic sometimes behaves differently when deployed as WAR instead of exploded.




Weblogic behaves like this because THIS IS EXACTLY what is defined in the J2EE specification. This is not a problem and is an expected and correct behavior as stated in specs. This is also mentioned in javadocs.

http://java.sun.com/products/servlet/2.5/docs/servlet-2_5-mr2/index.html

[]s
 
Crusading Chameleon likes the size of this ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic