Reputation: 6292
I am writing a library which uses some configurations. These configuration will not change frequently but will possible change in the future. Therefore I don't want to hard code them in the code.
What is the best way of doing this for a Java library? One possible solution is to inject it and hard code them in a DI configuration file I assume. But this requires code change as well.
What is the most typical way of doing this?
Many thanks
Upvotes: 2
Views: 289
Reputation: 7807
You can do this:
As file format you can use the Java Properties File.
And you can load it in this way
Properties props = new Properties();
props.load(YourClass.class.getResourceAsStream("name-of-your-prop-file.properties"));
Upvotes: 4
Reputation: 38414
Java Util Properties is a great tool for configuration. You can have the file embed in the jar, if you want to, and load it using getResourceAsStream()
method.
Upvotes: 1