jakarta-ee - 为什么在生成 ear 文件时使用父 pom 文件?

标签 jakarta-ee maven maven-2

我在 SO - How to add WAR inside EAR with Maven 上阅读了这个问题

在“joelittlejohn”的最高投票答案中 -

"Now create a parent module (with pom) and add the war module and the ear module to it. Make sure you set the parent of the war and ear modules corrently. When you run mvn package for this new parent, a war file will be built by the war module and an ear file (containing the war) will be built by the ear module."

但为什么要创建父 pom 呢?为什么不只用一个 pom.xml 创建一个标准的 maven 项目呢?这个单个 pom 文件包含依赖项和模块,然后从这个 pom 文件生成 .ear 文件?

类似的东西:

<plugin>
    <artifactId>maven-ear-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <finalName>MyEarFile</finalName>
        <version>5</version>
        <generatedDescriptorLocation>${basedir}/src/main/application/META-INF</generatedDescriptorLocation>
        <modules>
            <webModule>
                <groupId>com.your.group.id</groupId>
                <artifactId>your-war-artifact</artifactId>
                <uri>YouWarFile.war</uri>
                <bundleFileName>YouWarFile.war</bundleFileName>
                <contextRoot>/appname</contextRoot>
            </webModule>
        </modules>
    </configuration>

    <dependencies>
    <dependency>
    <groupId>com.your.group.id</groupId>
    <artifactId>your-war-artifact</artifactId>
    <version>your-war-version</version>
    <type>war</type>
    </dependency>
    </dependencies>

</plugin>

最佳答案

在 maven 中,为您要构建的每个 war 都有一个模块是很典型的。然后 .ear 文件将包含多个 war。因此,每个模块都有一个很好的职责分离。父 pom 只是将它们包装在一起。

关于jakarta-ee - 为什么在生成 ear 文件时使用父 pom 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9621522/

相关文章:

发图片到粉丝专页墙的Java代码

scala - Spark 斯卡拉 : JniBasedUnixGroupsMapping: Error getting groups for XXX: The user name could not be found

java - 让 Maven 复制构建 jar 中的其他文件(不是资源,而是任何包中的任何文件)?

java - 如何创建包含模块文件子集的 Maven Artifact ?

java - 带有 CMT 的 Ejb3 无状态 bean

java - 了解 java 日志文件

java - 寻找设计模式以将框架层彼此隔离

java - Jersey 的 ServletContainer init 方法可以被重写吗?

java - 在 IntelliJ 的 resources 文件夹中创建包

android - 无法在 Maven 中使用 ActionBarSherlock 将 Android 应用程序编译为 apklib