Java Maven 3:Maven 在 5 分钟内“mvn archetype:generate...”命令不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20165674/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 23:38:42  来源:igfitidea点击:

Maven 3: Maven in 5 minutes "mvn archetype:generate..." command NOT WORKING

javamaven-3

提问by aliteralmind

I installed Maven 3.1.1 for the first time. In the "Maven in 5 Minutes" getting-started guide

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

http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

it says to verify the installation with

它说要验证安装

mvn --version

mvn --version

I got the expected response:

我得到了预期的回应:

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"

In the next step, under "Creating a project" it says to create a new directory, open a command prompt in that directory, and execute

在下一步中,在“创建项目”下,它说要创建一个新目录,在该目录中打开命令提示符,然后执行

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

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

I created a directory called xjmaven, ran the command in it, and it's not working. This is the response:

我创建了一个名为 的目录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

I looked up the parameters groupId, artifactIdand archetypeArtifactId, and have tried some different values (as you can see above), but I still get the same BUILD FAILURE response.

我查找了参数groupIdartifactIdarchetypeArtifactId,并尝试了一些不同的值(如您在上面看到的),但我仍然得到相同的 BUILD FAILURE 响应。

I manually put the pom.xmlfile (from in the same webpage) in the xjmaven directory, and ran it again. It downloaded a bunch of stuff (although not to xjmaven), but then failed with this message:

我手动将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

Repeating the command gives this response:

重复该命令会给出以下响应:

[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

I deleted pom.xml(it's the only file in the directory...the stuff it downloaded is not there), and started over again. Everything happens (badly) as I write above.

我删除了pom.xml(它是目录中唯一的文件……它下载的东西不存在),然后重新开始。正如我上面写的那样,一切都发生了(糟糕)。



I remember trying Maven a few years ago, and could also not get past the getting-started stage.

我记得几年前尝试过 Maven,也无法通过入门阶段。

If anyone has some advice on how to get past this, it would be appreciated. Really frustrated.

如果有人对如何解决这个问题有一些建议,我们将不胜感激。真的很沮丧。

回答by Snehal Masne

You have some syntactical errors while executing the generategoal. Moreover, you need not create the pom.xml or any dir sturcture. You will notice that the generategoal creates a directory with the same name given as the artifactId.

在执行generate目标时,您有一些语法错误。此外,您不需要创建 pom.xml 或任何目录结构。您会注意到generate目标创建了一个与 artifactId 同名的目录。

e.g. you are missing the convention like -DgroupIdshould be com.company.app (not a big issue though), having space in -Darchetype ArtifactId, etc.

例如,您缺少-DgroupId应该是 com.company.app 之类的约定(虽然不是大问题),在 中有空间-Darchetype ArtifactId等。

I just tried below and it worked :

我只是在下面尝试过,它奏效了:

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

回答by Ergwun

Maybe you are using Windows PowerShell?

也许您正在使用 Windows PowerShell?

If so, you'll need to put quotes around the parameter definitions:

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

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