My POM contained:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-configuration2</artifactId>
<version>2.3</version>
</dependency>
Both sample codes from Quick start guide, Reading a properties file:
Configurations configs = new Configurations();
try
{
Configuration config = configs.properties(new File("config.properties"));
// access configuration properties
...
}
catch (ConfigurationException cex)
{
// Something went wrong
}
and Properties files, Using PropertiesConfiguration:
Parameters params = new Parameters();
FileBasedConfigurationBuilder<FileBasedConfiguration> builder =
new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
.configure(params.properties()
.setFileName("usergui.properties"));
try
{
Configuration config = builder.getConfiguration();
...
}
catch(ConfigurationException cex)
{
// loading of the configuration file failed
}
throwed:
java.lang.NoClassDefFoundError: org/apache/commons/beanutils/DynaBean
...
at org.apache.commons.configuration2.builder.fluent.Parameters.createParametersProxy(Parameters.java:307)
at org.apache.commons.configuration2.builder.fluent.Parameters.fileBased(Parameters.java:186)
at properties.PropertiesTest.testLoadAndStoreWithCommonsConfiguration(PropertiesTest.java:52)
...
Caused by: java.lang.ClassNotFoundException: org.apache.commons.beanutils.DynaBean
mvn dependency:tree
showed:
...
[INFO] +- org.apache.commons:commons-configuration2:jar:2.2:compile
[INFO] | +- org.apache.commons:commons-lang3:jar:3.6:compile
[INFO] | \- commons-logging:commons-logging:jar:1.2:compile
...
commons-configuration2
's POM contains:
...
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.3</version>
<optional>true</optional><
/dependency>
...
I added the following dependency to my POM and it worked:
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.3</version>
</dependency>
The latest POM of commons-configuration2
(as of Oct '21) declares <version>1.9.4
. I didn't try that but it may work with later versions of Commons Configuration.