2016-06-20 6 views
1

Ich habe versucht, apache commons configuration zu verwenden und auf ein Problem zu stoßen, wo es ein NoClassDefFoundError wirft. Es passiert auf Parameters.xml() Anruf. Unten finden Sie den vollständigen Code und die Ausnahmedetails, die mein IntelliJ generiert hat. Ich benutze jdk1.8.0_91. Ich schätze jede Hilfe bei der Lösung dieses Problems.Problem beim Lesen von XMLConfiguration-Dateien mit Apache configuration2

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"); 
     } 
    } 
} 

Ausnahmedetails:

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

Prozess beendet mit Exit-Code 1

Antwort

1

commons-configurations auf commons-beanutils abhängt, in dem die fehlende Klasse (org/apache/commons/beanutils/DynaBean) definiert ist.

Die erforderliche JAR fehlt wahrscheinlich in Ihrem Klassenpfad für die Laufzeit. Zusätzliche Informationen zu Ihrem Build-Prozess können helfen, das Problem genauer zu untersuchen (was ist auf Ihrem Build-Pfad, was ist auf Ihrem Klassenpfad, etc ...).

+0

Die Bohnengläser sind installiert und im Pfad. Ich habe das aufgegeben und benutze javax.xml für meine Bedürfnisse. – user3885927

0

So konnte ich dieses Problem beheben. Erstens, habe ich commons-beanutil meiner pom.xml-Datei:

<!-- Apache Commons Configuration --> 
<dependency> 
    <groupId>commons-beanutils</groupId> 
    <artifactId>commons-beanutils</artifactId> 
    <version>1.9.3</version> <!-- Add the latest version of BeanUtils here. --> 
</dependency> 

<dependency> 
    <groupId>org.apache.commons</groupId> 
    <artifactId>commons-configuration2</artifactId> 
    <version>2.0</version> <!-- Add the latest version of Apache Commons Configuration2 here. --> 
</dependency> 

<!-- Add any additional dependencies here. --> 

ich dann Apache BeanUtils und Apache Commons Konfiguration in meine Classpath kopiert (in meinem Fall war dies lib).

Download-URLs:

Verwandte Themen