Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powermock after log4j2.3 upgrade Could not reconfigure JMX java.lang.LinkageError

Im upgrading log4j from 1.x to 2.3. after setting up maven dependencies my project is builing and application is running fine.

But while builing, at test goal getting below mentioned error in variouse unit Test classes which are already there.

I could find a workaround by using @PowerMockIgnore. But worried of changing all the 100s of files which are already written.

ERROR StatusLogger Could not reconfigure JMX java.lang.LinkageError: loading constraint violation: loader "org/powermock/core/classloader/MockClassLoader@5fa95fa9" previously initiated loading for a different type with name "javax/management/MBeanServer" defined by loader "com/ibm/oti/vm/BootstrapClassLoader@7a5c7a5c".
like image 730
Sureshkumar Natarajan Avatar asked Jan 12 '17 09:01

Sureshkumar Natarajan


2 Answers

@see Mockito + PowerMock LinkageError while mocking system class

Try adding this annotation to your Test class:

@PowerMockIgnore("javax.management.*")

Worked for me.

And worked for me as well

like image 66
SScholl Avatar answered Oct 05 '22 04:10

SScholl


If you have many test classes and using powermock from version 1.7.0 you can specify a global config. See power mock configuration it comes with an example project where its use is demonstrated see example.

The configuration file should have:

powermock.global-ignore=javax.management.*
like image 38
nicoabie Avatar answered Oct 05 '22 03:10

nicoabie