views:

386

answers:

5

There are very good Perl libraries (e.g. Apache::Admin::Config) to operate on traditional unix config files like httpd.conf. Anyone know if there is good Java libraries to do the similar task?

I know there is a c library called Augeas with Java binding. Has anyone used that before?

Thanks!

A: 

Commons Configuration do manipulate configuration files.

Even it gives an option to save the manipulated properties in a new file also.

PropertiesConfiguration config = new PropertiesConfiguration("usergui.properties");
config.setProperty("colors.background", "#000000);
config.save("usergui.backup.properties);

Refer following link

http://commons.apache.org/configuration/userguide/howto_filebased.html#File-based_Configurations

Even, Apache Ant can also help you in manipulating the existing configuration files using your own PropertyHelper Implementation.

http://ant.apache.org/manual/properties.html#propertyHelper

EDITED after response in comments

Apache configuration do provide extensibility using bean Factory , you need to create the Apache config file httpd.conf domain class yourself , to make it working.

Defining the Apache modules in java you can have a look at Netloony source , service/apache/modules to have an idea on this.

http://netloony.sourceforge.net/userguide/intro.html

In netloony the config files values are presented in JTable, you need to use any configuration framework to persist it in file.

Hope this helps, I understand there is nothing out of Box in java presently to read apache conf files. I was trying to give a pointer where you can start with..

Thanks for information. But Apache Commons Configuration is not something I am looking for. This library can't manipulate apache http configration files which looks like:<pre>ServerTokens OSServerRoot "/etc/httpd"PidFile run/httpd.pidTimeout 300MaxKeepAliveRequests 100KeepAliveTimeout 15<IfModule prefork.c>StartServers 8MinSpareServers 5MaxSpareServers 20ServerLimit 256MaxClients 256MaxRequestsPerChild 4000</IfModule><IfModule worker.c>StartServers 2MaxClients 150MinSpareThreads 25MaxSpareThreads 75</IfModule>...</pre>
A: 

i dont think so. i searched around for this once and gave up.

smp7d
A: 

There does not seem to be an existing library for that purpose. You could, however, use Augeas, a library made for editing configuration files. Unlike the solution you are searching for, however, you need to tell Augeas how to interpret the configuration file beforehand, which might take more time than it's worth.

parent5446
A: 

Like others noted, there's not an easily found Java library, but I admit I've asked myself this same question a number of times in the past, as I hate messing with http.conf by hand.

Have you considered leveraging your knowledge of a PERL way? It's very easy to expose stateless functionality from PERL using soaplite like this.

Gabriel
What does SOAP have to do with Apache configuration?
daxim
The question implies knowledge of good PERL based Apache so I suggest an alternative means to the same end using soap::lite to call into PERL. Since transations on a config file don't generally carry any state (i.e. can be implemented by static functions)
Gabriel
You have no idea what you're talking about.
daxim
I feel like I'm missing something...
Gabriel
+2  A: 

I worked (programatically, for a project) with a lot of config files from many *nix projects like Apache's, Squid's, smtpd's, ldap's, PAM's etc. etc. I have come to realise there is deffinetly NOT a common format (grammar) but instead each project defines his own ad-hoc format and implements it's own custom parser. No common specification.

So the aproach on *nix projects config files si not "use the parser library" but rather "write your own parser".

There are however projects that try to stick to some sort of standard. Most common amog theese is the .ini file format (originated on OS/2 and windows) or GConf file format, for theese you may find readily available parsers.

Apache (read a-patch-e, as in made from many patches) is in the free-form class. It started with a var value format then, after a lot of "patching", added a warty-xmlish grammar for specifing scope and context of config vars.

  • If you just tweak parts of the config file, probably your best approach would be to scan the file looking for your desired config vars and then work with the file locally.
  • If however you need to config the whole file, better make a Java parser based on the C one.
clyfe