Configuration -- XML or Properties file?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Tuesday, September 6, 2005 12:12 PM

Hi all I am building a customer website on Jakarta tomcat 5.5.9 and struts. This is going to be a customer login site where the customers will be able to login in, see their bills online (run reports and pdf) and do some other functionalities like user management etc. I am trying to make the website an extensible and robust application. I have incorporated -- 1) a robust exception handling framework with struts declarative exception handling 2) a neat abstract factory pattern etc. I am putting as many configuration information in a file as possible. The various configuration properties that i have abstracted out -- to be put in a configuration file are as follows --     a) DAO queries    More>>

Hi all


I am building a customer website on Jakarta tomcat 5.5.9 and struts. This is going to be a customer login site where the customers will be able to login in, see their bills online (run reports and pdf) and do some other functionalities like user management etc.



I am trying to make the website an extensible and robust application. I have incorporated -- 1) a robust exception handling framework with struts declarative exception handling 2) a neat abstract factory pattern etc.



I am putting as many configuration information in a file as possible. The various configuration properties that i have abstracted out -- to be put in a configuration file are as follows --

    a) DAO queries

    b) parameter which tells the application whether the database is oracle, mysql, sybase etc etc so that those dao queries are picked from the file (by the way, i want to make my application database independent).

    c)other application parameters like --

           1) email settings (system admin emails).

           2) Jasper report settings.

           3) logging file settings.



my problem is there is a confusion whether to make this configuration file an XML file or a properties file ???


proponents of XML file say it is application independent, universally accepted, is so flexible, can hold hierarchical data, easy to maintain etc etc.

proponents of properties file (as a configuration medium) say -- it is a flat file with simple name-value pairs so it a very fast medium and since a parsed XML tree takes much RAM memory and since XML is so slow (and takes system resources), it is wise to use properties file as a configuration medium.


Can any expert please advice me which way to go now? should i go for a flat but somewhat clumsy method of properties file or a hierarchical, easily maintainable but slow and heavy XML file?





please advice me on this thread as soon as possible. any suggestions will be highly appreciated.

regards

Vaibhav Beohar

   <<Less

Re: Configuration -- XML or Properties file?

Posted By:   Shaun_Childers  
Posted On:   Monday, September 12, 2005 08:47 AM

As with most things in software, "it depends". Is this configuration information going to be loaded upon your application startup or will this be wrapped within a Singleton and loaded only once (but loaded the first time initialized)? In my experience I have seen both of these methods of configuration used practice as well as loading from a database table. Here are my opinions of the three choices:


1. Properties file: This is a quick/easy way to handle configuration. It lacks the ability for specifying anything but the most basic information (name=value pairs) and you usually must specify more parameters than usual in this manner due to potential clashes. For example:


datasource.oracle.url=...

datasource.oracle.username=...

datasource.mysql.url=...

datasource.mysql.username=...


Additionally, you must handle the name values in your code using String objects. This is very inflexible. Another important thing the keep in mind here is that runtime configuration changes would require knowing the location of the configuration file and modifying it and then rewriting it back. (JMX could possibly used to handle this aspect.)



2. Database Table: Allows for more complex storage method and for handling multiple sets of information through the use of primary keys into a value table(s). In other words, you can circumvent the above problem in #1 simple by having a primary key for each type of datasource and then index this into the value table by the key. Drawbacks are that you now have to open a database connection (use pooling) to read the values. A benefit is that it is much easier to allow for runtime changing of the configuration.


3. XML file: While it is also file-based (as in #1), it allows for handling multiple sets of the same type of data in a much more manageable manner. You can use a DTD to specify the parsing of the information and map this to a Java object (if you choose). The drawbacks of runtime changes are the same as #1 above.


I know there are other positives/negatives to each that I haven't mentiond, however in the end I think it's up to the architect of the application to apply the proper configuration approach based on things such as experience with each method, existing application within the organization, requirements of needing runtime changes without a server restart, etc.

I personally tend to use #2 and #3 most often with my work, however if I'm developing a simple app. and only need to handle configuration of a few pieces of data, I'll simply use a properties file.
About | Sitemap | Contact