xml file path

Hi,

I have a portlet which will read an xml file using 'DocumentBuilderFactoryI am placing the xml file in a specific folder in the portlet say xmlreader/book.xml.Now i want to read this xml file

If i give the file as

Document doc = docBuilder.parse(new File("/book.xml")); Parser will look in c:\book.xml

if i give

Document doc = docBuilder.parse(new File("book.xml")); Parser will look in 0

C:\cvsroot\liferay\ext\servers\jboss-tomcat\bin\book.xml.

Can anybody please tell how can i specify this path so tht parser will look into

C:/cvsroot/liferay/ext/servers/jboss-tomcat/server/default/deploy/xmlreader.war/book.xml

I am using JBoss+Tomcat as my server.and Liferay as my portal server

[I could see in the server log message which will specify the path

04:59:25,156 INFO [TomcatDeployer] deploy, ctxPath=/xmlreader, warUrl=file:/C:/

cvsroot/liferay/ext/servers/jboss-tomcat/server/default/deploy/1xmlreader.war/. when ever i deploy a new customized portlet.Is it possible to get this path in my portlet also]

[1092 byte] By [naduparambila] at [2008-2-22]
# 1

If you can get hold of the ServletContext and then to get hold of the resource relative to a context root, use ServletContext.getResourceAsStream("/book.xml").

Refer to http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContext.html#getResourceAsStream(java.lang.String)

To get hold of the ServletContext use

Servlet.getServletConfig().getServletContext()

Hope this helps,

--Sahoo

sahooa at 2007-7-16 > top of java,Enterprise & Remote Computing,AVK Portability...