使用maven插件时报错

Java代码   收藏代码
  1. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project oecp: Compilation failure  
  2. [ERROR] Unable to locate the Javac Compiler in:  
  3. [ERROR] G:\eclipse-jee\eclipse-jee-galileo-SR2-win32\eclipse\jre\..\lib\tools.jar  
  4. [ERROR] Please ensure you are using JDK 1.4 or above and  
  5. [ERROR] not a JRE (the com.sun.tools.javac.Main class is required).  
  6. [ERROR] In most cases you can change the location of your Java  
  7. [ERROR] installation by setting the JAVA_HOME environment variable.  
  8. [ERROR] -> [Help 1]  
  9. [ERROR]   
  10. [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.  
  11. [ERROR] Re-run Maven using the -X switch to enable full debug logging.  
  12. [ERROR]   
  13. [ERROR] For more information about the errors and possible solutions, please read the following articles:  
  14. [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException  

 

在eclipse下用maven编译时,可能会失败,爆出以下提示

Please ensure you are using JDK 1.4 or above and not a JRE (the com.sun.tools.javac.Main class is required).

这是因为eclipse默认是使用jre作为运行环境,而maven编译需要jdk作为运行环境

尝试修改eclipse.ini,加入如下语句

-vm
C:\Progra~1\Java\jdk1.6.0_21\bin\javaw.exe

无效

仔细看其爆出的提示,似乎将JAVA_HOME环境变量指向jdk目录即可,但依然不起作用。

 

其实有个简单办法,就是在eclipse里设置一个jdk的运行环境,然后将当前项目的运行环境设为jdk运行环境即可

步骤

window-preferences-java-installed jres

这里默认有个jre6的JRE定义(maybe你是jre5),一个方法是修改这个jre6,将其location指向你的jdk6目录

另一个办法是点击Add按钮,选择Standard VM,jre home选择你的jdk6目录。点击finish,这时发现多了一个JRE,将其勾上,以后新的项目,就默认使用这个JRE了

然后,进入项目的properties页面,选择Java build path,打开libraries标签,remove默认的jre6,add Libraries,选择JRE system library,选择你刚创建的jdk(已被默认选中),finish

现在运行maven 的编译,一切正常。

 


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值