Is there any Java Library to operate on unix config files like http.conf [closed]

2022-09-04 22:49:54

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!


答案 1

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 format then, after a lot of "patching", added a warty-xmlish grammar for specifing scope and context of config vars. var value

  • 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.

答案 2

Here is a Java library that I developed for my own purposes.

https://github.com/kkapelon/Apache-Httpd-conf-Reader

It is very early alpha. Use at your own risk. Any feedback would be appreciated.


推荐