编译Maven project报错:
NoSuchMethodError org slf4j helpers MessageFormatter format
Caused by: java.lang.NoSuchMethodError: org.slf4j.helpers.MessageFormatter.format(Ljava/lang/String;Ljava/lang/Object;)Lorg/slf4j/helpers/FormattingTuple;
检查jar包slf4j-api-1.6.1.jar包里面确实有MessageFormatter.format这个方法,所以不是因为缺少jar包。
然后网上百度了好久才找到解决办法:
-
<dependency> -
<groupId>org.slf4j</groupId> -
<artifactId>slf4j-log4j12</artifactId> -
<version>1.6.1</version> -
<type>jar</type> -
<scope>compile</scope> -
</dependency>
开始使用的版本为1.6.1的slf4j-log4j12-1.6.1.jar
后来更换成1.4.2版本的slf4j-log4j12-1.4.2.jar,因为我的maven里面就这两个版本的
-
<dependency> -
<groupId>org.slf4j</groupId> -
<artifactId>slf4j-log4j12</artifactId> -
<version>1.4.2</version> -
<type>jar</type> -
<scope>compile</scope> -
</dependency>
没有报这个错误了。
解决方法时这样说的:
Solution: If you are getting above exception it means whatever jar or dependency you are using is not backward compatible with old version. In my case I was using latest version of slf4j-log4j12 as below in maven dependency which was not compatible with old version:
中文:
解决方案:如果您正处于异常状态,这意味着无论您使用的JAR或依赖项与旧版本不向后兼容。在我的情况下我是用slf4j-log4j12新版本如下在Maven的依赖与旧版本不兼容。
就是使用的其他jar不能兼容1.6.1版本的slf4j-log4j12-1.6.1.jar,这个版本太高,降低版本就行了,不过我也没找出来为什么会这样。。。
本文解决了一个常见的Maven项目编译错误:NoSuchMethodError,具体为org.slf4j.helpers.MessageFormatter.format方法未找到的问题。通过调整slf4j-log4j12依赖的版本从1.6.1到1.4.2,成功解决了编译错误,避免了因新版本与项目中其他JAR包不兼容导致的问题。
5345

被折叠的 条评论
为什么被折叠?



