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 891517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:54:16+00:00 2026-05-15T13:54:16+00:00

How can I define some properties dynamically in Java. For now, I’m using a

  • 0

How can I define some properties dynamically in Java. For now, I’m using a properties file, but I need to change these properties before installation, so these properties should be set in a file outside the jar (or install) file.

These properties define my IBatis connection.

  • 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-15T13:54:16+00:00Added an answer on May 15, 2026 at 1:54 pm

    Keep going with the .properties and load the file as a resource.

    If it is in the classpath it would be found.

    What I use, because it is much easier to me is a resource bundle instead.

    edit

    If the file is in your classpath you can loaded it either as a resource with: Some.class.loadResource(...) or what I do is use a ResourceBundle which does basically the same.

    For instance if I have:

    import java.util.ResourceBundle;
    
    public class ResourceBundleTest {
        public static void main( String [] args ) {
            ResourceBundle bundle = ResourceBundle.getBundle("connection");
            for( String key: bundle.keySet() ){
                System.out.printf("bundle[%s]=%s%n",key, bundle.getString(key));
            }
        }
    }
    

    I can load that file if is in the class path. The property is outside, in “some/nested/dir”

    $ls -l some/nested/dir/
    total 8
    -rw-r--r--  1 oscarreyes  staff  35 Jun 25 12:06 connection.properties
    $cat some/nested/dir/connection.properties 
    name=Oscar
    lastName=Reyes
    age=0x1F
    

    If I run it without adding that directory to my classpath it wont work:

    $java ResourceBundleTest 
    Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name connection, locale es_ES
        at java.ut...ceBundle.java:1427)
        at java.ut...urceBundle.java:1250)
        at java.ut...ceBundle.java:705)
        at Resourc...st.java:6)
    

    But if I add the directory to my classpath, then the file will be found easily.

    $java -cp some/nested/dir/:.  ResourceBundleTest 
    bundle[lastName]=Reyes
    bundle[age]=0x1F
    bundle[name]=Oscar
    $
    

    In a similar fashion, you can have a .jar file, and put your .properties file wherever you want, you just have to include it in your classpath.

    The equivalent using properties would be:

    import java.util.Properties;
    
    public class LoadProperties {
        public static void main( String [] args ) throws java.io.IOException {
            Properties properties = new Properties();
            properties.load( LoadProperties.class.getResourceAsStream("connection.properties"));
            properties.list( System.out );
        }
    }
    

    But for some reason I prefer the resource bundle.

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

Sidebar

Ask A Question

Stats

  • Questions 445k
  • Answers 445k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I got this working by passing passing a classloader (this.getClass().getClassLoader())… May 15, 2026 at 6:50 pm
  • Editorial Team
    Editorial Team added an answer request and params in ActionController:Base are shortcuts to the ActionController::Request… May 15, 2026 at 6:50 pm
  • Editorial Team
    Editorial Team added an answer It still does this, here's what I get when I… May 15, 2026 at 6:50 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.