File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

Reading an XML file in a war file

Nitin Puthalath
Greenhorn

Joined: Jul 01, 2002
Posts: 3
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

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
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
 
subject: Reading an XML file in a war file