Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8479657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:05:37+00:00 2026-06-10T19:05:37+00:00

What is the best practice for reading config file(s) for your application. Which folders

  • 0

What is the best practice for reading config file(s) for your application. Which folders in tomcat server are “on the classpath”.

I tried placing my config file in the TOMCAT_HOME\conf but still I can’t read it from my servlet.

Tried using this (there is app.properties file in conf):

this.getClass().getClassLoader().getResourceAsStream("/app.properties");

I don’t have much properties maybe 10-15 I figured this won’t be problem. I remember when I was using jboss this wasn’t issue as this much.

In my app I also specify DB connection spring in the context.xml can I specify my properties in there as well somehow? Or how this works with tomcat?

I’d like to keep my properties seperate from my war/unpacked war.

Update

Reason for asking this is because I don’t know where my app will be deployed (at what location)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:05:38+00:00Added an answer on June 10, 2026 at 7:05 pm

    There are many different ways but it depends on your needs:

    To load a property file from $TOMCAT_HOME/conf directory you will need to access it using a java.io.File object since the class loader (as in this.getClass().getClassLoader().getResourceAsStream(...) is just able to load files (and classes) from your class path (under WEB-INF/classes, WEB-INF/lib or $TOMCAT_HOME/lib).

    The easiest example to load a file from the Tomcat’s config directory would be:

    File configDir = new File(System.getProperty("catalina.base"), "conf");
    File configFile = new File(configDir, "myconfig.properties");
    InputStream stream = new FileInputStream(configFile);
    Properties props = new Properties();
    props.load(stream);
    

    Notice that this approach will make your code dependent of Tomcat (the loading mechanism depends on the fact of a Tomcat’s system property being available). This is something that I wouldn’t recommend at all so if you move your property file to a folder inside your classpath then you should be able to load it the way you tried and your application could be deployed in any container.

    And, you could configure your properties as JNDI resources but it would be too much hassle to access them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The 'best practice' (as I see it) to atomically create a new file, is
What's the best practice for reading/saving/updating accented characters via HTML/MVC/LINQ-to-SQL? We have a web
After reading this answer , it looks like it is a best practice to
What is the best practice to check that my binary data at the file
I'm wondering if there is some recommended reading, best practice or opinion on how
Is there a best practice for one over the other? I've been reading the
What are the best practices for reading and writing binary data in Ruby? In
surfing on the web, reading about django dev best practices points to use pickled
Best practice is to use unique ivs, but what is unique? Is it unique
Short best practice question: If an object A is injected into another object B,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.