Apache Common Configuration 初步使用
今天玩了一把Apache common configuration,感觉挺哈皮。为了没有接触过这个工具的朋友少走弯路,我分享一下自己的经验。
1)从官网上下载一个common configuration的jar包,
http://commons.apache.org/configuration/downloads.html
我下的是commons-configuration-1.6.jar
2)至于怎么使用,自己看官网的说明文档吧,我也不是很懂。我主要拿它读取XML文件所以写了下面的代码
public static void main(String[] args) {
XMLConfiguration config = null;
try {
config = new XMLConfiguration("Tables.xml");
Object prop = config.getProperty("tables.table.name");
if(prop instanceof Collection)
{
System.out.println("Number of tables: " + ((Collection) prop).size());
}
} catch (ConfigurationException e) {
// TODO Auto-generated catch block
System.out.println("No file!");
e.printStackTrace();
}
}
}
3)报错了:No exception of type ConfigurationException can be thrown; an exception type must be a subclass of Throwable
这是因为少了一个jar包:commons-lang.jar
4)但是加了之后还是依然报错啊,缺包啊
java.lang.NoClassDefFoundError: org/apache/commons/logging/Log
还有一个忘记了
所以又加了两个,哈哈,成功了。
commons-collections.jar
commons-logging.jar
页:
[1]