如何使用maven-archetype-plugin创建项目? artefactId 等是什么?
我是 Maven 新手,正在使用 maven.apache.org 教程这里作为介绍。
在教程的“如何制作我的第一个 Maven 项目?”部分中,它教我们通过执行以下命令来生成 Maven 原型项目:
mvn archetype:generate
在 Maven 下载了许多工件后,它突然停下来,在命令行上问了以下问题:
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 149:
Apache教程没有描述这个提示。
我有两个问题:
1.上面的问题要求什么?应该如何回答才能使 mvn archetype:generate
过程继续进行?
2.传统上,人们使用mvn archetype:generate
来创建Maven项目吗?
--------------更新---------------------
关于我的第一个问题,我按下“Enter”键而不输入任何值并得到以下输出:
Choose version:
1: 1.0-alpha-1
2: 1.0-alpha-2
3: 1.0-alpha-3
4: 1.0-alpha-4
5: 1.0
6: 1.1
Choose a number: 6:
那是什么?
我在上面的例子中输入“1”,然后我得到以下内容:
Define value for property 'package': : :
Define value for property 'groupId': :
Define value for property 'artifactId': :
...
我如何定义它们?
I am new to Maven and am using the maven.apache.org tutorial here as an introduction.
In the "How do I make my first Maven project?" section of the tutorial, it teaches us to generate a Maven archetype project by executing the following command:
mvn archetype:generate
After Maven downloaded many artifacts, it suddenly stopped and asked the following question on the command line:
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 149:
The Apache tutorial does not describe this prompt.
I have two questions:
1. What is the question above asking for? How should it be answered such that the mvn archetype:generate
process continues?
2. Conventionally, do people use mvn archetype:generate
to create a Maven project?
--------------Update---------------------
With respect to my 1st question, I pressed "enter" without inputting any value and got the following output:
Choose version:
1: 1.0-alpha-1
2: 1.0-alpha-2
3: 1.0-alpha-3
4: 1.0-alpha-4
5: 1.0
6: 1.1
Choose a number: 6:
What is that?
I input "1" in above case, then I got the following things:
Define value for property 'package': : :
Define value for property 'groupId': :
Define value for property 'artifactId': :
...
How can I define them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
mvn archetype:generate
命令用于从现有模板创建项目。许多开发人员和项目组定义了多种原型。当您运行该命令时,maven 会执行以下操作:输入这些信息后,Maven将向您显示您输入的所有信息并要求您验证项目创建。如果您按 Y 然后输入,瞧,您的项目将使用您选择的工件和设置创建。
您还可以阅读 maven-archetype-plugin 的使用站点。
mvn archetype:generate
command is used to create a project from an existing template. There are several archetype's defined by many developers and project groups. When you run the command, maven does following things:After entering these information, Maven will show you all the information you entered and ask you to verify project creation. If you press Y and then enter, voila your project is created with the artifact and settings you chose.
You can also read maven-archetype-plugin's usage site.
它询问您想要使用哪种原型来为您的项目提供种子。如果您在出现提示时按“Enter”键,它将为您提供可用选项的列表。您可以使用 maven-archetype-quickstart 创建一个简单的项目(它可能会提示您在此之后选择一个存储库,在这种情况下,只需输入与您之后列出的第一个存储库相对应的编号)输入这个)。
回答您的另一个问题:是的,使用原型是建立新项目的常见方法。主要是因为各种项目/模块都有大量的原型。一旦您知道想要哪种原型,使用它来引导项目是最简单的入门方法。
It is asking you which archetype you want to use to seed your project. If you press "enter" at that prompt, it'll give you a list of available choices. You can use
maven-archetype-quickstart
to just create a simple project (it may prompt you to pick a repository after this, in that case, just enter the number that corresponds to the first repository listed after you enter this).To answer your other question: yes, using an archetype is a common way for setting up a new project. Mainly because there are plenty of archetypes out there for all kinds of projects/modules. Once you know which archetype you want, using it to bootstrap a project is the simplest way to get started.
快速浏览一下教程就会发现,您省略了 archetype:generate 命令的一些参数。这就是为什么它不知道选择哪个原型来生成教程项目并向您呈现所有可用的原型 (149)。
第一个问题:按回车键,您接受了原型插件的建议并选择#149。这个原型存在不同的版本,通常,正如 Chris 所说,可以选择最新的 - 这里是 1.1。
第二个问题:由于原型是一种可以节省大量工作的模板:是的,这很常见。但这不是唯一的方法 - 您始终可以从一个空项目开始。
A quick look at the tutorial reveales, that you omitted some parameters to the archetype:generate command. That's why it doesn't know which archetype to choose to generate your tutorial project from and presents all available archetypes (149) to you.
First question: By pressing return then you accepted the suggestion of the archetype plugin and choose # 149. This archetype exits in different versions and normally, as stated by Chris it's ok to choose the latest - here 1.1.
Second question: Since an archetype is kind of a template which can save you lots of work: Yes that's common. But not the only way - you can always start with an empty project.
您还可以使用简短形式
,甚至仅使用一个组:
如果以下工件存在于任何配置的目录中,您将获得以下工件(在第一种情况下):
或者,如果有多个候选者,您将获得多个建议。因此,您必须通过输入选择列表中显示的索引来选择它们。
请参阅 maven 网站 了解更多信息!
You can also use the short form
Or even only a group:
You will get the following artifact (in the first case) if it exists in any configured catalog:
Or you will get multiple suggestions if there are more then one candidates. So you will have to choose them by entering index displayed in the choise list.
Consult maven website for more!