如何使用maven-archetype-plugin创建项目? artefactId 等是什么?

发布于 2024-12-17 08:39:58 字数 1152 浏览 7 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

无需解释 2024-12-24 08:39:58

mvn archetype:generate 命令用于从现有模板创建项目。许多开发人员和项目组定义了多种原型。当您运行该命令时,maven 会执行以下操作:

  1. 下载 maven-archetype-plugin 的最新版本。
  2. 列出可用于创建项目的所有原型。如果您在调用命令时定义了原型,maven 会跳转到步骤 4。
  3. 默认情况下,maven 选择 ma​​ven-archetype-quickstart 原型,它基本上创建一个 maven Hello World 项目源类和测试类。如果你想创建一个简单的项目,你可以直接按回车键继续。如果您想创建特定类型的应用程序,您应该找到符合您需求的原型并输入该原型的编号,然后按 Enter 键。例如,如果您想创建一个 webapp 项目,您可以输入 153(这是该原型的当前数字,它可以随时更改。)
  4. 由于原型是模板,它们旨在反映当前的最佳实践,因此它们可以及时发展,因此他们有自己的版本。 Maven 会询问您要使用哪个版本的原型。默认情况下,maven 会为您选择最新版本。因此,如果您同意使用最新版本的原型,只需在这一步按 Enter 即可;
  5. 每个 Maven 项目(和模块)都有其 groupId、artifactId 和版本。然后 Maven 会分三步向您询问这些问题。 groupId:这在组织或项目中通常是唯一的。 artifactId:artifactId 通常是项目已知的名称。版本:这是命名难题的最后一块。(了解更多
  6. 最后,maven会询问您代码的包结构。最佳实践是创建反映 groupId 的文件夹结构,因此 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:

  1. Downloads maven-archetype-plugin's latest version.
  2. Lists all archetype's that can be used to create a project from. If you defined an archetype while calling the command, maven jumps to step 4.
  3. By default, maven chooses maven-archetype-quickstart archetype which basically creates a maven Hello World project with source and test classes. If you want to create a simple project, you can just press enter to continue. If you want to create a specific type of application, you should find the archetype matching your needs and enter the number of that archetype, then press enter. E.g. If you want to create a webapp project, you can enter 153 (this is the current number for this archetype, it can change in time.)
  4. Since archetypes are templates and they intend to reflect current best practices, they can evolve in time, thus they have their own versions. Maven will ask you which version of the archetype you want to use. By default, maven chooses latest version for you. so if you agree to use the latest version of an archetype, just press Enter at this step;
  5. Every maven project (and module) has its groupId, artifactId and version. Maven will then ask these to you in three steps. groupId: This is generally unique amongst an organization or a project. artifactId: The artifactId is generally the name that the project is known by. version: This is the last piece of the naming puzzle.(read more)
  6. Finally, maven will ask you the package structure for your code. A best practice is to create your folder structure that reflects the groupId, thus Maven sets this as default but you are free to change this.

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.

早乙女 2024-12-24 08:39:58

它询问您想要使用哪种原型来为您的项目提供种子。如果您在出现提示时按“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.

惯饮孤独 2024-12-24 08:39:58

快速浏览一下教程就会发现,您省略了 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.

叫嚣ゝ 2024-12-24 08:39:58

您还可以使用简短形式

mvn archetype:generate -Dfilter=org.example.group:example-artifact

,甚至仅使用一个组:

mvn archetype:generate -Dfilter=org.example.group:

如果以下工件存在于任何配置的目录中,您将获得以下工件(在第一种情况下):

<groupId>org.example.group</groupId>
<artifactId>example-artifact</artifactId>

或者,如果有多个候选者,您将获得多个建议。因此,您必须通过输入选择列表中显示的索引来选择它们。

请参阅 maven 网站 了解更多信息!

You can also use the short form

mvn archetype:generate -Dfilter=org.example.group:example-artifact

Or even only a group:

mvn archetype:generate -Dfilter=org.example.group:

You will get the following artifact (in the first case) if it exists in any configured catalog:

<groupId>org.example.group</groupId>
<artifactId>example-artifact</artifactId>

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文