Introducing OWNER, a tiny framework for Java Properties files.
5 Comments Published December 27th, 2012 in Java, OWNER API, Software Tags: bsd, configuration, framework, free, library, maven, opensource, owner, owner api, properties.I never liked to create “wrapper” classes for properties files. Do you know… those classes like:
public class MyAppConfig {
private static Properties p = ...;
public static String serverName() {
return p.getProperty("server.name");
}
public static int serverPort() {
return Integer.parseInt(p.getProperty("server.port"));
}
....
}
There’s nothing really bad about those classes. Only that they don’t do actually anything useful; plus, you need to keep things in sync with the properties file associated.
So, I always preferred to directly use Properties.getProperty() and pass a config properties to objects:
public class MyBusinessClass {
private final Properties conf;
public MyBusinessClass(..., Properties conf) {
this.conf = conf;
}
public void doSomething() {
String serverName = conf.getProperty("server.name");
int serverPort = Integer.parseInt(conf.getProperty("server.port"));
}
}
99% of the times, you need a configuration setting in a single point. So that’s good enough, and I don’t have to write (and keep in sync) a class that I can spare.
But… what about this?
public interface MyAppConfig extends Config {
@DefaultValue("foobar.com")
@Key("server.name");
String serverName();
@DefaultValue("80");
@Key("server.port");
int serverPort();
...
}
Add to this, a smart -annotation based- configuration loading:
@Sources({"file:~/.myapp.config", "file:/etc/myapp.config", "classpath:foo/bar/baz.properties"})
public interface MyAppConfig extends Config {
...
And a simple instantiation:
MyAppConfig conf = ConfigFactory.create(MyAppConfig.class);
And you have OWNER. A little configuration framework based on Java properties.
BSD license.
Credits to Google GWT, that does similar things with i18n.
5 Responses to “Introducing OWNER, a tiny framework for Java Properties files.”
- 1 Pingback on Feb 4th, 2013 at 18:43
Leave a Reply
Search
Calendar
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Nov | Feb » | |||||
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 | ||||||
Follow me
Archives
Categories
- Android (3)
- Apple (29)
- Books (7)
- Eclipse (14)
- Errors (5)
- Firefox (7)
- Git (3)
- Hardware (18)
- Horror Code (8)
- Internet (21)
- Java (104)
- JavaScript (9)
- Life, universe and everything (45)
- Lifehacks (26)
- Linux (52)
- Opinions (26)
- OSX (11)
- OWNER API (2)
- Python (1)
- Software (33)
- Speeches and Conferences (8)
- Unix (5)
- Web (23)
- Windows (19)
Tag Cloud
Android apple architecture Bash configuration CSS Development Düsseldorf Eclipse Git Google Hardware hdr How-To howto Java JAXB job Karmic Linux lion MacBook music Open Source Opinion OSX os x patterns Pitfalls Practices Resume Security Software Suspend TDD Testing tip tonemapped Tricks Ubuntu unix video Web Workaround XML
WP Cumulus Flash tag cloud by Roy Tanck and Luke Morton requires Flash Player 9 or better.
Blog License
Blogs I like
Books on the desk
Friends' Blogs
- Antonio Terreno & Valter Bernardini
- Bruno Bossola
- Daniele Galluccio
- Domenico Ventura
- Ed Schepis
- Fabrizio Gianneschi
- Luca Grulla
- Luigi Zanderighi
- Marcello Teodori
- Mida Boghetich
- Muralidharan Chandrasekaran
- Piero Ricca
- Renzo Borgatti
- Simone Bordet
- Simone Bruno
- Uberto Barbini
- Valvolog
- Webtide blogs (Greg Wilkins & Jan Bartel)
Links


















Excellent!
Hopefully I can be one of the first users, rather than rewriting the same boring code every time!
Let me know how it goes. I am planning to submit the jars to Maven Central asap; in 1.1-SNAPSHOT I already removed commons-lang dependency.
Smart and compact, nice work
Thank you, kind of hard to find a library like this these days, i stumbled on it accidentally (maybe i wasn;t looking good enough though), most of the people either go the usual way or hack one depending on their needs or yet again… use the one that comes with the framework. Good job and Thank you!:)