I was trying to use apache commons configuration and running into an issue where it throws a NoClassDefFoundError. It happens on Parameters.xml() call. Below is the full code and the exception details that my IntelliJ generated. I am using jdk1.8.0_91. I appreciate any help in solving this.
import org.apache.commons.configuration2.*;
import org.apache.commons.configuration2.ex.*;
import org.apache.commons.configuration2.builder.*;
import org.apache.commons.configuration2.builder.fluent.*;
public class TestDBA {
public static void main(String[] args)
{
try {
Parameters params = new Parameters();
FileBasedConfigurationBuilder<XMLConfiguration> builder = new FileBasedConfigurationBuilder<XMLConfiguration>(XMLConfiguration.class);
XMLBuilderParameters px = params.xml();
builder.configure(px.setFileName("myconfig.xml"));
XMLConfiguration config = builder.getConfiguration();
System.out.println(config.toString());
} catch (ConfigurationException cex) {
// loading of the configuration file failed
System.out.println("some error occurred");
}
}
}
Exception details:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/beanutils/DynaBean at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at com.sun.proxy.$Proxy0.(Unknown Source) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:739) at org.apache.commons.configuration2.builder.fluent.Parameters.createParametersProxy(Parameters.java:294) at org.apache.commons.configuration2.builder.fluent.Parameters.xml(Parameters.java:232) at TestDBA.main(TestDBA.java:16) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) Caused by: java.lang.ClassNotFoundException: org.apache.commons.beanutils.DynaBean at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 16 more
Process finished with exit code 1