Mockito, Java 9 and java.lang.ClassNotFoundException: sun.reflect.ReflectionFactory

前端 未结 3 1396
广开言路
广开言路 2020-12-10 14:52

My project is a Wildfly 13 application which uses Mockito testing library. The app is not using Java 9 module structure. As long as the server ran on Java 8 the tests worked

3条回答
  •  难免孤独
    2020-12-10 15:21

    As of Java 11, WildFly 14+ and Mockito 2.23.0+, adding jdk.unsupported module dependency to your WAR solves the problem. You can do this in two ways:

    A. META-INF/MANIFEST.MF

    Add the following line to META_INF/MANIFEST.MF of your WAR archive:

    Dependencies: jdk.unsupported
    

    Note that the file must end with a new line or carriage return.

    Here is how you'd typically do it with ShrinkWrap/Arquillian:

    @Deployment
    public static WebArchive createDeployment() {
        return ShrinkWrap.create(WebArchive.class, "my-app.war")
            .addPackages(true, Mockito.class.getPackage(), Objenesis.class.getPackage(), ByteBuddy.class.getPackage())
            .addAsManifestResource(new StringAsset("Dependencies: jdk.unsupported\n" /* required by Mockito */), "MANIFEST.MF");
    }
    

    B. WEB-INF/jboss-deployment-structure.xml

    Add the following content to WEB-INF/jboss-deployment-structure.xml of your WAR archive:

    
      
        
          
        
      
    
    

提交回复
热议问题