Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin

在使用Maven以及Eclipse的Maven插件时,我和同事遇到了一下几个问题,本着知其然知其所以然的学习精神,总结如下:

  1. Unrecognised tag
    问题
    由于我使用本地代理仓库,所以settings.xml设置如下:
       
       
    1. <profiles>
    2. <profile>
    3. <id>nexus</id>
    4. <repositories>
    5. <repository>
    6. <id>nexus</id>
    7. <name>Nexus</name>
    8. <url>http://localhost:8081/nexus/content/groups/public</url>
    9. <releases><enabled>true</enabled></releases>
    10. <snapshots><enabled>true</enabled></snapshots>
    11. </repository>
    12. </repositories>
    13. <pluginRepositories>
    14. <pluginRepository>
    15. <id>nexus</id>
    16. <name>Nexus</name>
    17. <url>http://localhost:8081/nexus/content/groups/public</url>
    18. <releases><enabled>true</enabled></releases>
    19. <snapshots><enabled>true</enabled></snapshots>
    20. </pluginRepository>
    21. </pluginRepositories>
    22. </profile>
    23. <!--激活配置-->
    24. <activeProfiles>
    25. <activeProfile>nexus</activeProfile>
    26. </activeProfiles>
    27. </profiles>
    但在Maven编译时报了如下异常:

    [WARNING] Some problems were encountered while building the effective settings
    [WARNING] Unrecognised tag: 'activeProfiles' (position: START_TAG seen ...\n\t... @269:18) @ C:\Documents and Settings\Administrator.ZQFGROUP.000\.m2\settings.xml, line 269, column 18
    [WARNING]

    解决
    这是因为错把activeProfiles配置到了profiles节点里了,应该把activeProfiles移到profiles之外,更多settings.xml配置信息请参考这里
  2. No goals
    问题

    Eclipse安装了Maven插件后,在项目的pom.xml上右键能看到如下:

    而我自作聪明地认为:Maven build 与 mvn compile 是等价的,于是我再点击"Maven build..."之后,“Goals”是空的,如:

    于是就报了这样的错误:

    [ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format:or:[:]:. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-site, site, post-site, site-deploy, pre-clean, clean, post-clean. -> [Help 1]

    解决
    解决方法至少有两种:
    • 再点击"Maven build..."之后,输入你要执行的“Goals”,如compile,clean,test等等;
    • 在pom.xml中配置默认的Goal,如:
           
           
      1. <build>
      2. <defaultGoal>clean</defaultGoal>
      3. </build>
      作为project的子节点。
  3.  not a JRE
    问题
    在使用pom.xml配置默认Goal的时,如果默认的Goal为clean就没问题,但如果是如:
       
       
    1. <build>
    2. <defaultGoal>clean compile</defaultGoal>
    3. </build>
    就会报错误:

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project Demo: Compilation failure
    [ERROR] Unable to locate the Javac Compiler in:
    [ERROR] C:\Program Files\Java\jre7\..\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.

    经过几番尝试,才发现并不是多个Goal的问题,而是compile Goal的问题。但使用命令的"mvn compile"又是OK的。
    几经折腾才发现错误里说的很清楚:Please ensure you are using JDK 1.4 or above and not a JRE",它需要的是JDK而不是JRE。我给的项目中使用的是公共JRE:

    解决
    修改Eclipse的配置,使用JDK:Eclipse->Window->Preferences->Java->Installed JREs

    Finish后,项目如:


转载地址: http://www.oseye.net/user/kevin/blog/251
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值