正确使用Apache Commons配置

And*_*huk 17 java configuration

我的代码如下:

package org.minuteware.jgun;

import org.apache.commons.configuration.*;

class ConfigReader {
    public void getconfig() {
        Configuration config;
        try {
            config = new PropertiesConfiguration("gun.conf");
        } catch (ConfigurationException e) {
            e.printStackTrace();
        }
        String day = config.getString("sync_overlays");
        System.out.println(day);
    }
}
Run Code Online (Sandbox Code Playgroud)

Eclipse在此代码中存在两个问题:

  1. 对于package org.minuteware.jgun;它说的线The type org.apache.commons.lang.exception.NestableException cannot be resolved. It is indirectly referenced from required .class files
  2. 对于} catch (ConfigurationException e) {它说的线No exception of type ConfigurationException can be thrown; an exception type must be a subclass of Throwable

在Java中发现了ConfigurationException?,但提供的解决方案没有帮助.

Bal*_*usC 38

Apache Commons Configuration的核心具有以下运行时依赖性:

也可以将它们放在类路径中.您的特定问题是由缺少Lang依赖性引起的.

  • 问题是我有Lang3,但遗留的Lang2是必需的.很奇怪,它不支持版本3. (8认同)