异常处理:Idea打包maven项目报错找不到编译环境

来源:互联网 发布:网络博客游戏怎么举报 编辑:程序博客网 时间:2024/05/19 15:39

在idea中给新建的maven项目打包,teminal中输入mvn package提示打包失败,报错:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project springWebProject: Compilation failure

[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

查询相关资料大致意思是项目中没有添加SDK依赖。
于是查看project structure发现相关SDK依赖已经添加。如图:
project structure

  后来查找原因发现原来操作系统中有两套jdk环境(操作系统环境变量中配置的是jdk 1.8),项目pom配置声明使用jdk 1.7并且project structure引用的也是jdk1.7 没有问题,然而通过terminal进行maven打包时,idea调用了操作系统环境变量中配置的jdk 1.8版本。与项目配置声明的冲突,所以出现上述问题。更改操作系统环境变量中的jdk路径,解决这一问题。