编译或运行UTgen生成的测试用例失败的解决办法
现象描述
当项目使用JDK 11及以上版本时,运行时出现“module java.base does not "opens java.lang" to unnamed module”报错信息。
图1 报错信息

可能原因
pom.xml文件或者build.gradle文件中未添加启动参数。
处理步骤
在pom.xml文件或者build.gradle文件中添加编译启动参数。
例如:在pom.xml文件中添加编译启动参数。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
<build> <plugins> <plugin> <!-- 编译插件 --> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>${java.version}</source> <target>${java.version}</target> <encoding>${project.build.sourceEncoding}</encoding> <compilerArgs> <arg>--add-exports</arg> <arg>java.desktop/sun.awt.util=ALL-UNNAMED</arg> </compilerArgs> </configuration> </plugin> <plugin> <!-- 测试插件 --> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.0.0-M5</version> <configuration> <argLine> --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.desktop/sun.awt.util=ALL-UNNAMED </argLine> </configuration> </plugin> </plugins> </build> |
父主题: FAQ