maven错误:无法使受保护的最终java.lang.Class java.lang.ClassLoader.defineClass

问题描述 投票:0回答:1

当我尝试使用 Maven 运行自动化测试用例时,出现以下错误。我运行了 project>run as> maven install

    Failed to execute goal net.serenity-bdd.maven.plugins:serenity-maven-plugin:1.9.16:aggregate (serenity-reports) on project flightmode: Execution serenity-reports of goal net.serenity-bdd.maven.plugins:serenity-maven-plugin:1.9.16:aggregate failed: An API incompatibility was encountered while executing net.serenity-bdd.maven.plugins:serenity-maven-plugin:1.9.16:aggregate: java.lang.ExceptionInInitializerError: null


[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>net.serenity-bdd.maven.plugins:serenity-maven-plugin:1.9.16
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/XXXXX/.m2/repository/net/serenity-bdd/maven/plugins/serenity-maven-plugin/1.9.16/serenity-maven-plugin-1.9.16.jar
[ERROR] urls[1] = file:/C:/XXXX/.m2/repository/net/serenity-bdd/serenity-core/1.9.16/serenity-core-1.9.16.jar
[ERROR] urls[2] = file:/C:/XXXX/.m2/repository/com/google/guava/guava/23.6-jre/guava-23.6-jre.jar
[ERROR] urls[3] = file:/C:/XXXXX/.m2/repository/com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar
........

[ERROR] : Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @7a972f12
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException
  • 系统Java版本:JDK 17.0.12
  • Maven版本:3.8.3

我也尝试使用 Java 21 运行,但仍然面临同样的问题, 还在 eclipse.ini 文件中添加了以下内容,仍然面临同样的问题

-Djava.security.manager=allow
--illegal-access=warn
--add-opens=java.base/java.lang=ALL-UNNAME
java eclipse maven java-8 pom.xml
1个回答
0
投票

尝试使用

maven-surefire-plugin
插件

<dependency>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.5.1</version>
    <configuration>
        <argLine>--add-opens java.base/java.lang=ALL-UNNAMED</argLine>
    </configuration>    
</dependency>
© www.soinside.com 2019 - 2024. All rights reserved.