“程序包xxx已在模块xxx中声明,但该模块未导出它”编译报错的解决方法
现象描述
当项目使用JDK 11及以上版本时,出现如下报错信息。
java: package xxx is not visible (package xxx is declared in module java.base, which does not export it)
可能原因
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 | <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.base/sun.util.calendar=ALL-UNNAMED</arg> </compilerArgs> </configuration> </plugin> </plugins> </build> |
父主题: FAQ