1 Reply Latest reply: Dec 8, 2005 3:38 AM by 843844 RSS

    xml file path

      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
      Can anybody please tell how can i specify this path so tht parser will look into
      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]
        • 1. Re: xml file path
          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
          Hope this helps,