• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Help loading XML config file?

Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If you've been following my previous posts, you'll notice that I had a problem of trying to load a properties file (stored under WEB-INF), until I edited my build script and made it place the log4j.properties file under WEB-INF/classes, and then used the following code to load in the properties file:

Although, this works for loading property files into my webapp's CLASSPATH, my new question (just for those who think that I am trying to post the same question twice, which I am not), is this:

I also have a servlet which uses init params to load & parse XML config files (which are located under: %TOMCAT_HOME%/mywebapp/WEB-INF/ )

My new question is:

How do I use the getResourceAsStream() method to load this particular XML file which is not located under WEB-INF/classes? Its located under just WEB-INF.

Also is there a way to convert this InputStream into a File?

Here's my original piece of code (which works when undeployWars="true", I am trying to get it to work when undeployWars="false"):

What I thought I could do was something like this inside the try / catch:

Now, the problem is... I think that there will be definitely be a pathing issue for WEB-INF/attributes-config.xml when using getResourceAsStream() (I am guessing because of my attempts with the Log4jInitServlet postings). Also, how would one convert an InputStream to a File?


How to convert "is" and "xmlConfigFile"?


[ December 22, 2006: Message edited by: James Dekker ]
Posts: 67748
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please confine this discussion to a single topic.
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic