Friday, February 25, 2011

How to configure your application on the start up using Constretto

Since i am new to using Constretto, i thought of sharing my experince in understanding the usage of Constretto.

First i sarted following following tutorila to write helloworld time application and then to move towords more advanced topics.

Opps , at the start of the tutorila seems a problems

Totorial is written using MVN automated build system. I am new to MVN as well. But i have little understanding of its behaviour , so it will help me to contitune this tutorial successfully.

Following line at the begining of the tutorial might means something similart to following.

"It allows you to “tag” configuration values, so that Constretto could choose the correct value at runtime."

Constretto gives tag for each and every configuration value. So during hte runtime using the this tag value , it can deside which configuration value to be used. i am wondering why they have mentioned at the begining of the torrorial. Because, we know that, if there is a configuration file with lot of values , then there should be some mechanisum to identify each and every configuration value identically. So this is nothing strange right :\

But next line says something very important for me, it says that , Constretto supports different configuration mechanisums. Hmm, before looking in to tutorial , i didn't know even one configuration mechanisums. So it says development community is already following different configuration mechanisums.

"It also works as a bridge between different configuration formats, and currently Java property files, Ini files, and Java Beans are
supported."

I usually prefere reading introduction when ever i am about to something new. So here no different :)

First step is to crete mvn project. i have used eclipse IDE and m2eclipse plugin installed on it. Alos you can take any other path as you wish.

When you are done with crating project skelton using MVN , you will find System.out.println("Helloworld"); Line at sample class created by you using mvn simple project skelton.

OK, now we are going to have fun with Constretto technique of configuring the project.

OK i added following code in to App.java class

ConstrettoConfiguration config =
new ConstrettoBuilder()
.createPropertiesStore()
.addResource(new DefaultResourceLoader().getResource("classpath:test.properties"))
.addResource(new DefaultResourceLoader().getResource("file:test2.properties"))
.done()
.createIniFileConfigurationStore()
.addResource(new DefaultResourceLoader().getResource("classpath:test.ini"))
.done()
.createObjectConfigurationStore()
.addObject(new Object())
.done()
.createSystemPropertiesStore()
.getConfiguration();

This is not a big deal, just copy this code segment from this tutorial https://github.com/constretto/constretto-core

Now in the above code sample you can see that configuration file is given in so many different ways, So i would like to know how classpath.test.propeties gives the path to property file.

Ok putting classpath.test.properties file in so many different places helped us to resolve this issue. Now comes the most interesting part of this problem. I want to put this file in the location that i am interested reather than in the place it is given still using classpath.test.properties method.

No comments:

Post a Comment