Specifying location of a resource file under Tomcat

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?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
whichitAuthor Commented:
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.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.