简体   繁体   中英

Apache Commons Configuration: ClassNotFoundException: org.apache.commons.beanutils.DynaBean

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM