Maven 3: Maven 在 5 分钟内 “mvn 原型:生成...”命令不起作用

2022-09-03 16:21:11

我第一次安装了 Maven 3.1.1。在“5 分钟内完成 Maven”入门指南

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

我查找了参数 和 ,并尝试了一些不同的值(如上所示),但我仍然得到相同的构建失败响应。groupIdartifactIdarchetypeArtifactId

我手动将文件(来自同一网页)放在xjmaven目录中,然后再次运行它。它下载了一堆东西(虽然不是),但随后失败,并显示以下消息:pom.xmlxjmaven

[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,也无法通过入门阶段。

如果有人对如何克服这一点有一些建议,我们将不胜感激。真的很沮丧。


答案 1

也许你正在使用Windows PowerShell?

如果是这样,您需要在参数定义两边加上引号:

mvn archetype:generate "-DarchetypeGroupId=org.apache.maven.archetypes" "-DgroupId=com.mycompany.app" "-DartifactId=my-app"

答案 2

执行目标时出现一些语法错误。此外,您无需创建pom.xml或任何dir sturcture。您会注意到,该目标创建一个与 artifactId 同名的目录。generategenerate

例如,你错过了约定俗成的惯例,比如应该 com.company.app(虽然不是一个大问题),有空间,等等。-DgroupId-Darchetype ArtifactId

我刚刚尝试了下面,它的工作原理:

mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

推荐