IDEA intellij maven项目打包报错Please ensure you are using JDK 1.4 or above and not a JRE解决方法!

在使用intellij打包maven项目时报以下异常:

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project com.xxx: Compilation failure

Unable to locate the Javac Compiler in:
E:\JDK1.8\jdk_1.8.0_20\..\lib\tools.jar
Please ensure you are using JDK 1.4 or above and not a JRE (the com.sun.tools.javac.Main class is required).
In most cases you can change the location of your Java installation by setting the JAVA_HOME environment variable.

报错原因一:

项目pom文件中配置的maven插件版本过低,比如我当时是配置的2.3.2,无法支持Java1.8版本的。

解决办法:修改maven插件的版本为较新版本。

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

报错原因二:

编译maven项目使用的JDK->JRE->lib中没有tools.jar,我也很奇怪为什么会这样。

解决办法:

只需要在找到你自己电脑上Java JDK的路径,比如我是C:\Program Files\Java\jdk1.8,然后进入lib里面把tools.jar复制到JRE的lib中,然后在你的intellij中重新配置一下JDK(不重新配置的话tools.jar无法添加进来使用),然后右键项目,选择Rebuild Module XXX,之后再进行打包就没问题了。

最后实在不行的话只能修改JAVA_HOME,然后右键项目选择Show in Explorer进入到项目目录,自己通过maven命令打包了。

目前就遇到了这两种情况,有其他的问题可以留言共同探讨。

 

 

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值