当前位置: 代码网 > it编程>编程语言>Java > idea修改language level版本实现方式

idea修改language level版本实现方式

2025年12月21日 Java 我要评论
1、前言使用场景,当原本jdk1.8版本的编译环境时,突然加载一个jdk17的项目时,项目reload或maven install时经常报错language level版本问题,以下是解决方案。2、操

1、前言

使用场景,当原本jdk1.8版本的编译环境时,突然加载一个jdk17的项目时,项目reload或maven install时经常报错language level版本问题,以下是解决方案。

2、操作步骤

2.1 修改系统环境变量

多个jdk为了方便切换,我的环境变量是这样设置的,java_home负责切换版本,path变量就跟平时配置的一样。

需要到哪个版本就切换java_home里面的变量就行。

2.2 修改maven的配置

maven的配置文件在安装目录的setting.xml,需配置多个jdk的配置。 

<profiles>里面配置多个jdk,<activeprofiles>里面负责切换配置。

如下方配置:

<?xml version="1.0" encoding="utf-8"?>
<settings xmlns="http://maven.apache.org/settings/1.2.0"
          xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"
          xsi:schemalocation="http://maven.apache.org/settings/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
  <plugingroups>
  </plugingroups>
  
  <proxies>
  </proxies>
  
  <servers>
  </servers>
  
 <mirrors>
      <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
        <mirrorof>central</mirrorof>
    </mirror>
    <mirror>
      <id>aliyun</id>
      <mirrorof>central</mirrorof>
      <name>aliyun-public</name>
      <url>https://maven.aliyun.com/repository/public/</url>
    </mirror>
    <mirror>
      <id>aliyun-spring</id>
      <mirrorof>spring</mirrorof>
      <name>aliyun-spring</name>
      <url>https://maven.aliyun.com/repository/spring</url>
    </mirror>

    <!-- 中央仓库在中国的镜像 -->
    <mirror>
      <id>maven.net.cn</id>
      <name>one of the central mirrors in china</name>
      <url>http://maven.net.cn/content/groups/public/</url>
      <mirrorof>central</mirrorof>
    </mirror>
    <!-- 中央仓库1 -->
    <mirror>
        <id>repo1</id>
        <mirrorof>central</mirrorof>
        <name>human readable name for this mirror.</name>
        <url>https://repo1.maven.org/maven2/</url>
    </mirror>

  </mirrors>
  
  <!-- 以下是jdk配置 -->
  <profiles>
    <profile>
         <id>jdk-1.8</id>
         <activation>
             <activebydefault>true</activebydefault>
             <jdk>1.8</jdk>
          </activation>
          <properties>
              <maven.compiler.source>1.8</maven.compiler.source>
              <maven.compiler.target>1.8</maven.compiler.target>
              <maven.compiler.compilerversion>1.8</maven.compiler.compilerversion>
          </properties>
    </profile>
      <profile>
          <id>jdk-17</id>
          <activation>
              <activebydefault>true</activebydefault>
              <jdk>17</jdk>
          </activation>
          <properties>
              <maven.compiler.source>17</maven.compiler.source>
              <maven.compiler.target>17</maven.compiler.target>
              <maven.compiler.compilerversion>17</maven.compiler.compilerversion>
          </properties>
      </profile>
  </profiles>
  <activeprofiles>
<!--    <activeprofile>jdk-1.8</activeprofile>-->
      <activeprofile>jdk-17</activeprofile>
  </activeprofiles>


</settings>

2.3 idea配置修改

(1)模块设置菜单。

(2)模块设置jdk。

(3)idea设置:file->setting,把图片中的修改为你要的jdk版本。

(4)重载maven

(5)校验,跟(1)的步骤一样进入model setting,如下图所示:

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com