1

I have several different projects and all of them currently hardcode server names, DB user and passwords.

I have found all of the places that need to be changed in order to point to a new server, but there are at least 50 instances where the same change is required, which looks like terrible design.

I would like to change this so that this information is centralized so no one else would have to go hunting for this again. I have read about setting environment variables, but preferably I would like to include the information with the projects themselves such as reading from some sort of configuration file.

How should I approach this?

MxLDevs
  • 19,048
  • 36
  • 123
  • 194

1 Answers1

2

How about properties file? You can use it like this as suggested here :

public class App {

    public static void main( String[] args )
    {
        Properties prop = new Properties();

        try {
               //load a properties file
               prop.load(new FileInputStream("config.properties"));

               //get the property value and print it out
               System.out.println(prop.getProperty("database"));
               System.out.println(prop.getProperty("dbuser"));
               System.out.println(prop.getProperty("dbpassword"));

        } catch (IOException ex) {
            ex.printStackTrace();
        }

    }
}
Yohanes Gultom
  • 3,782
  • 2
  • 25
  • 38