[英]Java: package java.time does not exist using Intellij
我在 Intellij IDEA 社区版本 2022.3.1 中使用 JDK11 为我的 selenium 项目创建了一个 maven 项目。 现在在运行 testng.xml 文件时出现错误java: package java.time does not exist
。
在 Project Settings->Modules->Sources->Language Level 中,我使用了值 8 和 11,但仍然出现相同的错误。
我预计在执行 testng.xml 文件时,我的测试应该运行时没有任何错误。
在我的 baseClass 中,我正在使用driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
并且还导入了 package import java.time.Duration
什么会导致这个?
在社区的帮助下,这个问题的解决方案是:
File->Project Settings->Modules->Sources->Language Level 将值设置为 11
File-> Settings->Build, Execution, Deployment->Compiler->Java Compiler 将“Target bytecode version”设置为11
如果您正在使用 pom.xml 文件并进行构建,则设置以下内容:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> <source>11</source> <target>11</target> </configuration> </plugin>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.