Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading an XML file in a war file

 
Nitin Puthalath
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have a war in which i have a xml directory as follows :

APP/WEB-INF
APP/xml/abc.xml

I want to read the xml file in the model classes as they contain configuration parameters.
The war is not exploded in Weblogic 7.0.
How do i read the XML file.
I tried using the class Loader.But it does not work.
I can very well get the xml file using the following code :
java.net.URL url = config.getServletContext().getResource("/xml/eventRules.xml");

String filepath=url.toString();
out.println("File Path"+filepath);
But this would mean I will have to pass the parameter always to the model classes.
Any way to achieve this.
also
1) Can you explode a war in Weblogic
2) Is there any system property which i can use to get the Application context path in Weblogic 7.0
Thanks & Regards,
Nitin
 
Guy Allard
Ranch Hand
Posts: 776
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To get the full OS specific path to your base do:

String path = context.getRealPath("/");

If the war is not exploded, that might not help you much 'tho.

Regards, Guy
 
Kunaal A Trehan
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Create a file under /WEB-INF and use getResourceAsStream(Val);
Val=getServketContext() + /WEB-INF/FILENAME

I think this solve ur problem

Kunal
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic