my dog learned polymorphism
The moose likes Servlets and the fly likes Reading an XML file in a war file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Reading an XML file in a war file" Watch "Reading an XML file in a war file" New topic

Reading an XML file in a war file

Nitin Puthalath

Joined: Jul 01, 2002
Posts: 3
Hi All,
I have a war in which i have a xml directory as follows :


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 : 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.
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,
Guy Allard
Ranch Hand

Joined: Nov 24, 2000
Posts: 776
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

Joined: Feb 04, 2004
Posts: 63

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

I think this solve ur problem

I agree. Here's the link:
subject: Reading an XML file in a war file
jQuery in Action, 3rd edition