No compiler is provided in this environment . Perhaps you are running on a jre rather than a JDK?

背景:利用IDEA+maven构建一个非web的spring boot项目(Windows电脑下),代码完成时,使用mvn package打包报错: No compiler is provided in this environment . Perhaps you are running on a jre rather than a JDK?

在网上试了很多方法,有一种方法可行:

			
				maven-compiler-plugin
				
					1.8
					1.8
					true
					C:\Program Files\Java\jdk1.8.0_171\bin\javac
				
			

还有一种方法,这个错误其实是maven找不到javac命令,maven是根据系统的java路径去找的,在命令行中输入where java显示:

C:\Program Files (x86)\Common Files\Oracle\Java\javapath

这个是系统的java路径,不是自己安装的java8路径。再次输入where javac却显示找不到javac路径,到刚刚的C:\Program Files (x86)\Common Files\Oracle\Java\javapath中去查看,确实没有javac命令:

No compiler is provided in this environment . Perhaps you are running on a jre rather than a JDK?_第1张图片

这就是为什么一直报错的原因了,解决办法是在系统变量里进行如下设置:

No compiler is provided in this environment . Perhaps you are running on a jre rather than a JDK?_第2张图片 

最后记得重启一下电脑即可。

 

 

你可能感兴趣的:(maven)