我在编程方面有点经验,但对Maven来说是个新手。在我的最新项目中,我正在使用Apache Commons API(配置、cli等)。它可以编译,但在运行时会引发NoSuchMethod异常。
我的依赖项如下所示:
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-configuration2</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.4</version>
</dependency>
这是发生错误的方法:
private Configuration parseConfig(String path) {
File configFile = new File(path);
if(!configFile.exists() || configFile.isDirectory()) {
// Error config file path invalid
CustomLogger.warn("ERROR file not found");
}
Configurations configs = new Configurations();
Configuration config = null;
try {
config = configs.properties(configFile);
}
catch (ConfigurationException cex) {
// Something went wrong
CustomLogger.warn("Config Exception");
cex.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return config;
}
发生错误的线路/部件/块准确为:
try {
config = configs.properties(configFile);
}
堆栈跟踪是:
java.lang.NoSuchMethodError: org.apache.commons.beanutils.PropertyUtilsBean.addBeanIntrospector(Lorg/apache/commons/beanutils/BeanIntrospector;)V
at org.apache.commons.configuration2.beanutils.BeanHelper.initBeanUtilsBean(BeanHelper.java:631)
at org.apache.commons.configuration2.beanutils.BeanHelper.<clinit>(BeanHelper.java:89)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.sun.proxy.$Proxy0.<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.fileBased(Parameters.java:185)
at org.apache.commons.configuration2.builder.fluent.Configurations.fileParams(Configurations.java:602)
at org.apache.commons.configuration2.builder.fluent.Configurations.fileParams(Configurations.java:614)
at org.apache.commons.configuration2.builder.fluent.Configurations.fileBasedBuilder(Configurations.java:132)
at org.apache.commons.configuration2.builder.fluent.Configurations.propertiesBuilder(Configurations.java:238)
at org.apache.commons.configuration2.builder.fluent.Configurations.properties(Configurations.java:282)
at com.core.utils.CustomConfiguration.parseConfig(CustomConfiguration.java:130)
我错过了什么?有几篇关于堆栈溢出的帖子建议在依赖项中包含“commons beanutils”。这样做并没有改变任何事情。感谢您的帮助。