如何创建一个空的多模块Maven项目? [英] How to create an empty multi module Maven project?

查看:1148
本文介绍了如何创建一个空的多模块Maven项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我经常在网上找到一个 pom.xml 文件,其中包含 pom 打包和复制粘贴它以创建我的父项目。然后我曾经在父目录中运行 archetype:create 来创建子模块,但是 archetype:create 已经被弃用了那么。

Right now I usually find a pom.xml file on the web that has a pom packaging and copy and paste it to create my parent project. Then I used to run archetype:create inside the parent directory to create sub modules but archetype:create has become deprecated since then.

关于如何创建新的Maven多模块项目的任何建议?

Any recommendations on how to create new Maven multi-module projects?

推荐答案

我发现这样做最简单的方法是使用 pom-root 原型来创建顶级pom,然后重复使用 archetype:generate 分别创建每个模块。这将自动将模块添加到根pom(聚合器)并将根pom设置为每个模块的父pom(编辑:显然一些原型可以具有硬编码的父级,但它适用于 maven -archetype-quickstart )。

The easiest way I've found to do this is to use the pom-root archetype to create the top-level pom and then repeatedly use archetype:generate to create each module individually. This will automatically add the modules to the root pom (aggregator) and set the root pom as the parent pom for each module (edit: apparently some archetypes can have a hard-coded parent, but it works for maven-archetype-quickstart).

以下是细分:


  1. 创建顶级根:

  1. Create the top-level root:

mvn archetype:generate \
-DarchetypeGroupId=org.codehaus.mojo.archetypes \
-DarchetypeArtifactId=pom-root \
-DarchetypeVersion=RELEASE


  • cd 到新创建的根目录中。

  • cd into your newly created root dir.

    对于每个模块:

    mvn archetype:generate \
    -DarchetypeGroupId=org.apache.maven.archetypes \
    -DarchetypeArtifactId=maven-archetype-quickstart \
    -DarchetypeVersion=RELEASE
    


  • 请注意上面的 -DarchetypeVersion = RELEASE 将自动为你se最新版本的原型。您可能希望为每个命令添加 -DgroupId = ... ,以避免重复自己。

    Note that -DarchetypeVersion=RELEASE above will automatically use the latest version of the archetype. You may want to add -DgroupId=... to each of those commands to avoid repeating yourself.

    这篇关于如何创建一个空的多模块Maven项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆