我是第一次安装Maven 3.1.1。在“5分钟内行家”入门指南中
http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
它说来验证安装mvn --version
我得到了预期的答复:
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 11:22:22-0400)
Maven home: C:\applications\programming\apache-maven-3.1.1
Java version: 1.6.0_17, vendor: Sun Microsystems Inc.
Java home: C:\applications\programming\java_6_17\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
下一步,在“创建项目”下,它表示要创建一个新目录,在该目录中打开命令提示符,然后执行
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
我创建了一个名为
xjmaven
的目录,并在其中运行命令,但该目录不起作用。这是响应:[R:\jeffy\programming\sandbox\xjmaven]mvn archetype:generate -DgroupId=xbnjava -DartifactId=XBN-Java -Darchetype ArtifactId=maven-archetype-quickstart -DinteractiveMode=false
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.251s
[INFO] Finished at: Sat Nov 23 12:11:56 EST 2013
[INFO] Final Memory: 2M/4M
[INFO] ------------------------------------------------------------------------
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (R:\jeffy\programming\sandbox\xjmaven). Please verify you invoked Maven from the correct directory. -> [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/MissingProjectException
我查找了参数
groupId
,artifactId
和archetypeArtifactId
,并尝试了一些不同的值(如您在上面看到的),但是我仍然得到相同的BUILD FAILURE响应。我手动将
pom.xml
文件(来自同一网页)放在xjmaven目录中,然后再次运行。它下载了一堆东西(尽管不是xjmaven
),但随后失败,并显示以下消息:[INFO] Generating project in Interactive mode
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/archetypes/true/1.0/true-1.0.jar
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Skipping Maven Quick Start Archetype
[INFO] This project has been banned from the build due to previous failures.
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 45.047s
[INFO] Finished at: Sat Nov 23 12:04:01 EST 2013
[INFO] Final Memory: 7M/17M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:generate (default-cli) on project XBN-Java: The desired archetype does not exist (org.apache.maven.archetypes:true:1.0) -> [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
重复该命令将给出以下响应:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Quick Start Archetype 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.2:generate (default-cli) @ XBN-Java >>>
[INFO]
[INFO] <<< maven-archetype-plugin:2.2:generate (default-cli) @ XBN-Java <<<
[INFO]
[INFO] --- maven-archetype-plugin:2.2:generate (default-cli) @ XBN-Java ---
[INFO] Generating project in Interactive mode
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Skipping Maven Quick Start Archetype
[INFO] This project has been banned from the build due to previous failures.
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.444s
[INFO] Finished at: Sat Nov 23 12:04:32 EST 2013
[INFO] Final Memory: 8M/14M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:generate (default-cli) on project XBN-Java: The desired archetype does not exist (org.apache.maven.archetypes:true:1.0) -> [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
我删除了
pom.xml
(这是目录中的唯一文件...下载的内容不存在),然后重新开始。正如我在上面所写,一切都会发生(严重)。我记得几年前尝试过Maven,也无法超越入门阶段。
如果有人对如何克服这个问题有任何建议,将不胜感激。真的很沮丧。
最佳答案
也许您正在使用Windows PowerShell?
如果是这样,则需要在参数定义两边加上引号:
mvn archetype:generate "-DarchetypeGroupId=org.apache.maven.archetypes" "-DgroupId=com.mycompany.app" "-DartifactId=my-app"