在 Intellij Idea 中,咱们须要设置 Settings 中的 Java Compiler 和 Project Structure 中的 Language Level 中的 jdk 版本为本身目前使用的版本,不然会常常提示咱们 jdk 版本不正确致使的语法错误。
<!--more-->
好比配置为 jdk1.8 :apache
可是在 Maven 项目中,Java Compiler 和 Language level 中的设置会自动变回到 pom.xml 文件中设置的 jdk 版本或者默认的 jdk1.5 版本。因此咱们须要在 pom.xml 文件中修改 jdk 版本的配置或者本身添加配置:maven
<!-- 这里通常有 maven 的默认配置,修改便可 --> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties>
或者:ui
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.7.0</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build>
注意: 若是 properties 和 build 里面都有配置的话,那么 properties 会覆盖掉 build 里面的配置,即以 properties 里面的配置为准。spa