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

  • Home
  • SEARCH
  • 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 5960707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:51:49+00:00 2026-05-22T18:51:49+00:00

I am reading a properties file from the Tomcat\conf\somename.properties directory using String demo =

  • 0

I am reading a properties file from the Tomcat\conf\somename.properties directory using

String demo = System.getProperty("catalina.base") +
                  File.separator + "conf" + File.separator + "somename.properties";

This is working perfectly fine with Tomcat. But, there can be scenario where client may use any other server like Glassfish or Websphere, in that case I won’t be able to get System.getProperty("catalina.base").

How should I solve it properly? I’m able to do that using ResourceBundle but for that I have to keep my properties file in my build, which I don’t want. I just want to read my properties file from outside my build.

  • 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-05-22T18:51:49+00:00Added an answer on May 22, 2026 at 6:51 pm

    There are basically two ways.

    1. Just add its path to the runtime classpath so that you can get it from the classpath the usual way. In case of Tomcat, you can add external folders to the runtime classpath by specifying it in the shared.loader property of /conf/catalina.properties. E.g.

      shared.loader = ${catalina.home}/conf

      Or better, don’t be server-specific

      shared.loader = /path/to/folder

      Other servers also supports adding external folders to the classpath, consult their documentation.

      This way you’ll be able to get an InputStream of it from the classpath as follows:

      InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream("/config.properties");
      Properties properties = new Properties();
      properties.load(input);
      // ...
      

    2. Add another server-independent system property yourself, you can set as a VM argument.

      -Dconfig.location=/path/to/folder

      In case of Tomcat, you can set it as JAVA_OPTS environment variable, or edit the catalina.bat startup file or edit the Windows Service settings (when it’s installed as Windows Service), etc. Other servers supports similar constructs as well.

      This way you can obtain it as follows

      File file = new File(System.getProperty("config.location"), "config.properties");
      InputStream input = new FileInputStream(file);
      Properties properties = new Properties();
      properties.load(input);
      // ...
      

    Either way you choose, when distributing your application, you should document it properly so that the serveradmin can configure it accordingly.


    Unrelated to the problem, the ResourceBundle is not the right way to read configuration properties files. It’s intented for localized content for internationalization.

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

Sidebar

Related Questions

I am thinking of using sed for reading .properties file, but was wondering if
I am reading properties file from java DAO implementation for loading properties object as
I have created a simple application of reading mail properties from a nsf file
I'm having some issues with loading a (.properties) file from the webcontent folder in
I developing a plugin which reads from a .properties file for the database connection,
In my ASP.NET4 app, I'm reading in data from a file. The data represents
Reading the bottom of the documentation, specifically: You can still retrieve properties of deleted
I want map my object from text file, the text file contents are like
i specified the below properties in cfg file. <property name=hibernate.cache.use_second_level_cache>true</property> <property name=hibernate.cache.provider_class> net.sf.ehcache.hibernate.EhCacheProvider</property> In
I'm reading some data from an XML format and putting it in my classes

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.