16

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".
  • 1
    I think you might want to read the answer I put up on that question: http://stackoverflow.com/questions/41603303/powermockignore-at-project-level ... as in my opinion: the problem you are facing now ... well, that is the price that one pays for using PowerMock. The "bigger" your project gets, the higher chances are that you spend serious time on such powermock-framework problems; instead of worrying about real problems in your production code. – GhostCat Jan 12 '17 at 11:53

2 Answers2

28

@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

SScholl
  • 598
  • 6
  • 19
3

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.*
nicoabie
  • 2,684
  • 1
  • 20
  • 19
  • 1
    Note, spaces and double quotes are not allowed in the configuration.properties file. See: https://github.com/powermock/powermock/issues/989 – Navigatron Sep 28 '21 at 08:38