[英]java.lang.NoSuchFieldError: NO_FORMAT when tunning maven surefire junit tests
When trying to run junit tests from maven (maven surefire plugin) I get the following error: 尝试从Maven(Maven surefire插件)运行junit测试时,出现以下错误:
java.lang.NoSuchFieldError: NO_FORMAT
This error seems to come from any call to my log4j logger. 该错误似乎来自对我的log4j记录器的任何调用。 So when I have a class with a log4j class variable log
, like: 因此,当我有一个带有log4j类变量log
类时,例如:
public class SomeClass {
private Logger log = Logger.getLogger(SomeClass.class);
....
}
then a call to 然后致电
log.info(String msg);
results in the above error. 导致上述错误。 I tried to make sure that the basic configuration is setup when running the junit tests, such as 我尝试确保在运行junit测试时已设置基本配置,例如
@Before
public void setup() {
BasicConfigurator.configure();
someclass = new SomeClass();
}
but that does not solve this problem. 但这不能解决这个问题。 Removing all the log
calls solves the problem, but that is not a very nice solution. 删除所有log
调用可以解决问题,但这不是一个很好的解决方案。
Any idea why this problem occur? 知道为什么会出现此问题吗? Many thanks. 非常感谢。
尝试升级/降级您的log4j依赖项。
我不确定这是否有帮助,但是我将尝试检查是否在类路径中有多个Log4j依赖项,即我将运行mvn dependency:tree
并可能将其输出到临时文件,例如mvn dependency:tree > deps.txt
然后分析我的依赖关系。
To me the problem was that I had activated an arquillian profile as well. 对我来说,问题在于我还激活了一个Arquillian个人资料。 Make sure you only activate the right one to run the maven tests :-) 确保只激活正确的一个以运行Maven测试:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.