Specifying location of a resource file under Tomcat

Posted on 2006-04-19
Last Modified: 2010-04-01
Hello. I'm trying to establish what would be the most elegant way of specifying the location of an xml file which we are using (in this case for the commons Digester api).

Most of our property files are kept in the /WEB-INF/classes/resources directory, and are retrieved using the ResourceBundle class. This is fine, but this case is different as we are using the file in a different way.

We have achieved our goal by simply putting the xml file into the resources folder, and specifying the full path to the file in a constants file, ie /LogWindedWebRoot/WEB-INF/classes/resources/ourFile.xml - but something tells me this isn't the best practice. What would be the best or most common location to store such a file, and the best solution for retreiving it?

Question by:whichit
    LVL 92

    Accepted Solution

    Depends on what the api is expecting ie. InputStream, Url, File etc.
    Unless it is expecting a file then somewhere under classes would be the best spot and load it via the classloader
    If its expecting a file then put them somewhere under WEB-INF and use getRealPath() method to get the actual loacation.
    LVL 11

    Assisted Solution

    WEB-INF/classes/resources or any other custom folder inside WEB-INF/classes is normally considered a good approach. It also depends upon the usage of the application.

    What i mean to say with usage is, say for ex: you have one web application named "myapps". If you have 3 instances considering the same application source "myapps" and you need different xml configuration file for each instance, then WEB-INF/classes... is not a good option. Here u need instance dependent location..somewhere outside of application sources.

    Hope it clears.

    Author Comment

    Yep, thanks guys, I got the name of the file and location from a property file (under the resources directory), and then loaded the file with the ClassLoader.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Suggested Solutions

    Title # Comments Views Activity
    Javamail API 3 128
    Converting a Hibernate Query to use parameters 5 103
    tomcat users xml 7 92
    sortaSum challenge java 17 167
    After several days of searching and hunting for limited documentation, I wanted to share this guide to hopefully save someone the hassle of trying to figure this out on their own. I have tested this on Xendesktop 7.1 and PS 4.5 running simultaneous…
    This post first appeared at Oracleinaction  ( Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now