怎么在IDEA-Maven项目中设置jdk版本

怎么在IDEA-Maven项目中设置jdk版本

今天就跟大家聊聊有关怎么在IDEA-Maven项目中设置jdk版本,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

比如配置为 jdk1.8 :

怎么在IDEA-Maven项目中设置jdk版本

怎么在IDEA-Maven项目中设置jdk版本

但是在 Maven 项目中,Java Compiler 和 Language level 中的设置会自动变回到 pom.xml 文件中设置的 jdk 版本或者默认的 jdk1.5 版本。所以我们需要在 pom.xml 文件中修改 jdk 版本的配置或者自己添加配置:

<!-- 这里一般有 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>

或者:

<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 里面的配置为准。

看完上述内容,你们对怎么在IDEA-Maven项目中设置jdk版本有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注行业资讯频道,感谢大家的支持。