16

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>
    ...
1
  • 4
    The dependency is in the POM since at least 2011, but declared as "optional". I suppose it's the reason why gradle does not include it per default. The reason for optional is not clear: github.com/apache/commons-configuration/commit/… Commented Jan 13, 2022 at 8:18

2 Answers 2

22

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>

UPDATE

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.

Sign up to request clarification or add additional context in comments.

1 Comment

The dependency is in the POM since at least 2011, see my other comment under the question itself.
-2
<dependency>
    <groupId>commons-beanutils</groupId>
    <artifactId>commons-beanutils</artifactId>
    <version>1.9.4</version>
</dependency>

After adding the code in pom.xml, I found that it doesn't work.

I downloaded the jar, put it into lib content under Web-INF, then it works.

I think that Maven's plugin log causes it to die, it can not update or delete the jar automatically.

1 Comment

Putting dependencies into lib folders is old-school and definitely not the canonical Maven way. Which Maven plugin are you referring to?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.