解决:javac: 无效的目标发行版: 10

maven编译时候报的错误如下:

    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 1.660 s
    [INFO] Finished at: 2017-06-14T16:18:54+08:00
    [INFO] Final Memory: 18M/216M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project utils: Compilation failure
    [ERROR] Failure executing javac, but could not parse the error:
    [ERROR] javac: 无效的目标发行版: 1.8
    [ERROR] 用法: javac <options> <source files>
    [ERROR] -help 用于列出可能的选项
    [ERROR] -> [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.


maven编译报错:

1, 看自己的Java环境变量是否正确配置:

JAVA_HOME :       C:\Program Files\Java\jdk1.8.0_92           //安装的Jdk路径
PATH:            %JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;     

CLASS_PATH:   .;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;  //注意前面的那个点和后面的分号

按下"window"+R 输入cmd 按下"ENTER"  输入java和javac 出现下图说明配置成功:

2,确认自己的maven配置的jdk的版本正确:

按下"window"+R 输入cmd 按下"ENTER"  输入mvn -v 出现下图说明配置正确:

3,"ctrl+shift+alt+s" , 打开project settings,确定项目的jdk和sdk是是否配置正确:

  3.1,project 下的project SDK,是否为项目需要的jdk:


  3.2 确定SDK是否选中:


  3.3 language level不能比项目的jdk版本高:

  3.4确定modules下dependencies配置的jdk是否正确:

4, "run/dug configurations"  >>>需要运行的项目名称 >>>>>>runner  >>>>JRE配置是否正确:


 5 , 按下 "ctrl + alt + s "  打开settings确定Java  compiler 的 Target bytecode version 是否选中项目需要的jdk版本:

6, 确定D:\apache-maven-3.2.5\conf下的settings的jdk版本配置正确:

     <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>
     
          <repositories>
            <repository>
              <id>jdk17</id>
              <name>Repository for JDK 1.8 builds</name>
              <url>http://www.myhost.com/maven/jdk18</url>
              <layout>default</layout>
              <snapshotPolicy>always</snapshotPolicy>
            </repository>
          </repositories>
        </profile>

7, 确定pom.xml配置是否正确:

    <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-compiler-plugin</artifactId>
       <version>2.3.2</version>
       <configuration>
          <source>1.8</source>
          <target>1.8</target>
          <encoding>UTF-8</encoding>
       </configuration>
    </plugin>

 

补充说明:经过一段时间的使用,我又发现了最根本的问题,直接修改pom.xml文件知识让你能够启动不报错而已! 它真正的原因是maven的runner的jre的环境依然在使用jdk10,所以才导致的冲突!只有在这里修改maven的runner的jre才能从本质上解决这个问题!

猜你喜欢

转载自blog.csdn.net/qq_39607449/article/details/83339341