java学习笔记6 - 使用commons configuration管理配置文件
Commons Configuration是一个java应用程序的配置管理类库。可以从properties或者xml文件中加载软件的配置信息,用来构建支撑软件运 行的基础环境。在一些配置文件较多较的复杂的情况下,使用该配置工具比较可以简化配置文件的解析和管理。也提高了开发效率和软件的可维护性。
官方主页:http://commons.apache.org/configuration/
它目前支持的配置文件格式有:
Properties files
XML documents
Windows INI files
Property list files (plist)
JNDI
JDBC Datasource
System properties
Applet parameters
Servlet parameters
我使用的是目前最新版本1.9,以调用 Properties格式的文件为例,使用方法如下:
基本用法:
1.加载jar包,我使用maven自动加载,pom.xml配置如下:
configUtil.get("/common/velocity.properties", "input.encoding");