2017-06-28 17 views
1

FileBasedConfigurationBuilderを設定して、PropertiesConfigurationで作業できるようにしようとしていますが、NoClassDefFoundErrorが表示されています。 はここに私のコードNoClassDefFoundErrorを取得してPropertiesConfigurationを設定しようとしたとき

public class Config { 
    private static Properties properties; 
    private static PropertiesConfiguration config; 

    public static void setUp(String path) throws ConfigurationException, IOException { 
    if (config == null) { 
     FileBasedConfigurationBuilder<PropertiesConfiguration> builder = 
      new FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class) 
      .configure(new Parameters().properties() 
       .setFileName("myConfig.properties") 
       .setThrowExceptionOnMissing(true) 
       .setListDelimiterHandler(new DefaultListDelimiterHandler(',')) 
       .setIncludesAllowed(false)); 

     config = builder.getConfiguration(); 

     File file = new File(path); 
     FileReader reader = new FileReader(file); 
     config.read(reader); 
    } 
    } 
} 

とスタックトレースです:

java.lang.NoClassDefFoundError: org/apache/commons/beanutils/BeanIntrospector 
    at java.lang.Class.forName0(Native Method) 
    at java.lang.Class.forName(Unknown Source) 
    at com.sun.proxy.$Proxy38.<clinit>(Unknown Source) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) 
    at java.lang.reflect.Constructor.newInstance(Unknown Source) 
    at java.lang.reflect.Proxy.newProxyInstance(Unknown Source) 
    at org.apache.commons.configuration2.builder.fluent.Parameters.createParametersProxy(Parameters.java:294) 
    at org.apache.commons.configuration2.builder.fluent.Parameters.properties(Parameters.java:245) 

答えて

0

あなたのクラスが欠落していることを意味するものではありませんjava.lang.NoClassDefFoundErrorのを取得している(その場合には、あなたが取得したいですjava.lang.ClassNotFoundException)。クラスを読み込もうとしているときに、クラス定義を読み込んでいるときにClassLoaderがエラーになりました。

静的初期化子の中にtry/catchを入れて例外を見ます。あなたがそこにいくつかのファイルを読んでそれはあなたのローカル環境とは異なる場合、それはおそらく問題の原因です(ファイルが見つからない、権限がないなど)。あなたのクラスパス(commons-beanutils)から(BeanIntrospectorクラスが含まれています)Apacheのコモンズ豆utilsのjarファイルを逃すようで

関連する問題