创建新的 Maven 项目时找不到所需的原型

Cant find desired archetype when creating new Maven project

我正在尝试使用以下命令在终端中创建一个新的 Maven 项目:

mvn archetype:generate -DgroupId=com.my.domain -DartifactId=myproject -DarchetypeArtifactId=wildfly-javaee7-webapp-archetype -DinteractiveMode=false

所以我正在尝试使用 Wildfly 原型 wildfly-javaee7-webapp-archetype

我收到以下错误...

[INFO] Generating project in Batch mode
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/wildfly-javaee7-webapp-archetype/1.0/wildfly-javaee7-webapp-archetype-1.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 17.860 s
[INFO] Finished at: 2016-03-31T14:35:27+02:00
[INFO] Final Memory: 16M/188M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.4:generate (default-cli) on project standalone-pom: The desired archetype does not exist (org.apache.maven.archetypes:wildfly-javaee7-webapp-archetype: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

... 这意味着,Maven 正试图在 https://repo.maven.apache.org 下载原型,这是不正确的,因为原型是由 http://mvnrepository.com/artifact/org.wildfly.archetype.

提供的

如何更改来源或如何添加其他来源?还是我遗漏了一些不同的东西?

您需要定义archetypeGroupId, otherwise, it will default to groupId of Maven default archetypes. Also, you need to define the archetypeVersion

在这种情况下,您需要 archetypeGroupId=org.wildfly.archetypearchetypeVersion=8.2.0.Final (for example)。

因此,您应该:

mvn archetype:generate -DgroupId=com.my.domain -DartifactId=myproject -DarchetypeGroupId=org.wildfly.archetype -DarchetypeArtifactId=wildfly-javaee7-webapp-archetype -DarchetypeVersion=8.2.0.Final -DinteractiveMode=false

作为旁注,repo.maven.apache.orgmvnrepository.com 都是 Maven Central 并且包含相同的工件。

如果其他人在遵循已接受的答案后遇到问题,请尝试将版本降低到 -DarchetypeVersion=8.1.0.Final