Issue
I recently upgraded my Java version to Java11 for 8 and since then i am seeing this error:
java.lang.NoClassDefFoundError: Could not initialize class com.github.tomakehurst.wiremock.core.WireMockApp
at com.github.tomakehurst.wiremock.WireMockServer.(WireMockServer.java:73) at com.github.tomakehurst.wiremock.WireMockServer.(WireMockServer.java:112)
Below you can find my usage of wiremock:
@RunWith(PowerMockRunner.class)
@PrepareForTest(ConfigManagement.class)
@PowerMockIgnore({"javax.management.*","com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*","com.github.tomakehurst.*"})
public class MandateEventsJobTest {
private static HikariDataSource dataSource;
private WireMockServer wireMockServer;
@Before
public void setUp() throws Exception {
wireMockServer = new WireMockServer(8080);
wireMockServer.start();
stubFor(get(urlPathMatching("/ping")).willReturn(aResponse().withBody("pong")));
...
I'm not able to resolve this issue. Please help.
Solution
Seems like there's an issue with PowerMockRunner in java version 9 or above. I added even more packages to @PowerMockIgnore({})
and it worked:
@PowerMockIgnore({"javax.management.","com.sun.org.apache.xerces.", "javax.xml.", "org.xml.", "com.sun.org.apache.xalan.", "javax.net."})
Answered By - Rajat Pratap
Answer Checked By - Candace Johnson (JavaFixing Volunteer)