• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Tomcat classpath

 
Ranch Hand
Posts: 47
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a web app deployed (name: ROOT) in Tomcat 6.0 in which I want to place my xml file in one of the sub folders (i.e. ROOT/Folder1/myXML.xml). I want to read this XML for which I have to set the classpath to ROOT/Folder1. How do I set this classpath? I tried setting it up in common.loader in catalina.properties but to no avail. Please give examples as well.

Thanks in advance.

Regards,
Ankit
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, the easiest way to read this file isn't via the classpath. Use request.getResourceAsStream("/Folder1/MyXML.xml").

By default a webapp's classpath is the WEB-INF/classes directory and the jars in WEB-INF/lib plus whatever classpaths have been inherited from the container. So to use an arbitrary folder as a classpath component, you'd have to add a customer classloader to the webapp. It's easier just to access the file as a resource.
 
Ankit Nagpal
Ranch Hand
Posts: 47
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tim.

Although I could not find the method getResourceAsStream() but you gave me the direction to resolve this issue. I have used application.getRealPath() to get the absolute path for reading the XML file.
 
reply
    Bookmark Topic Watch Topic
  • New Topic