使用maven插件时总是报错:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project oecp: Compilation failure [ERROR] Unable to locate the Javac Compiler in: [ERROR] G:\eclipse-jee\eclipse-jee-galileo-SR2-win32\eclipse\jre\..\lib\tools.jar [ERROR] Please ensure you are using JDK 1.4 or above and [ERROR] not a JRE (the com.sun.tools.javac.Main class is required). [ERROR] In most cases you can change the location of your Java [ERROR] installation by setting the JAVA_HOME environment variable. [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. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
根据网上搜的内容,我的eclipse是3.5的,在eclipse的window-preferences-java-installed jres里把jdk由1.6改成1.5,不报错了...
--------------------------我是分割线 下面是转贴内容-------------------------------------------------------------
在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 的编译,一切正常。
内容转自: http://hi.baidu.com/goosebaby/blog/item/d56313ec05cb52c12f2e21ce.html