maven在eclipse中的问题

  1. Unrecognised tag
    问题
    因为我使用本地代理仓库,因此settings.xml设置以下:html

    <profiles>
    <profile>
    <id>nexus</id>
    <repositories>
    <repository>
    <id>nexus</id>
    <name>Nexus</name>
    <url>http://localhost:8081/nexus/content/groups/public</url>
    <releases><enabled>true</enabled></releases>
    <snapshots><enabled>true</enabled></snapshots>
    </repository>
    </repositories>
    <pluginRepositories>
    <pluginRepository>
    <id>nexus</id>
    <name>Nexus</name> 
    <url>http://localhost:8081/nexus/content/groups/public</url>
    <releases><enabled>true</enabled></releases>
    <snapshots><enabled>true</enabled></snapshots> 
    </pluginRepository> 
    </pluginRepositories>
    </profile> 
    <!--激活配置-->
    <activeProfiles>
    <activeProfile>nexus</activeProfile>
    </activeProfiles>
    </profiles>

    但在Maven编译时报了以下异常:java

    [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]web

    解决
    这是由于错把activeProfiles配置到了profiles节点里了,应该把activeProfiles移到profiles以外,更多settings.xml配置信息请参考这里apache

  2. No goals
    问题
    Eclipse安装了Maven插件后,在项目的pom.xml上右键能看到以下:

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

    因而就报了这样的错误:maven

    [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]post

    解决
    解决方法至少有两种:ui

    • 再点击"Maven build..."以后,输入你要执行的“Goals”,如compile,clean,test等等;this

    • 在pom.xml中配置默认的Goal,如:url

      <build>
      <defaultGoal>clean</defaultGoal>
      </build>

      做为project的子节点。spa

  3.  not a JRE
    问题
    在使用pom.xml配置默认Goal的时,若是默认的Goal为clean就没问题,但若是是如:


    就会报错误:

    [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后,项目如:

  4. system propery is not set

    错误:-Dmaven.multiModuleProjectDirectory system propery is not set.

    新建一个环境变量M2_HOME指向你的maven安装目录
    M2_HOME=D:\study\apache-maven-3.3.3
    而后在Window->Preference->Java->Installed JREs->Edit
    在Default VM arguments中设置
    -Dmaven.multiModuleProjectDirectory=$M2_HOME

5.      Launching New_configuration

项目上右击->Run/Debug Settings->删除 new_Configuration.

maven参考资料:

http://tangyanbo.iteye.com/category/220107

http://www.cnblogs.com/xing901022/p/4170248.html

http://blog.csdn.net/gebitan505/article/details/46234359