1

我知道这听起来可能是错误的做法,但我正在尝试拥有一个 Maven POM(模块),它在安装时将打包为 WAR,但另外,作为包含单个 WAR 的 EAR。

澄清一下:我希望将我项目中的每个现有 WAR 包装在它自己的EAR 中。

我的愿望背后的原因是因为我正在考虑重组我们打包发布的 WAR 的方式,以便每个都包含在 EAR 中(但仍然生成一个独立的 WAR 工件以便于开发)。我不热衷于创建一个依赖于 WAR 的新模块并将其打包到 EAR 中,因为我有大量的 WAR。

目前我正在尝试这个,对于我现有的 WAR 模块之一,但没有成功使用分类器

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <parent>
        ...
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>se-index-webapp</artifactId>
    <packaging>war</packaging>

    <build>
        <plugins>

            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    ...
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-ear-plugin</artifactId>
                <version>2.7</version>
                <configuration>
                    <finalName>search-index.ear</finalName>
                    <classifier>ear</classifier>
                    <unpackTypes>war</unpackTypes>
                    <modules>
                        <webModule>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>${artifactId}</artifactId>
                            <uri>search-index.war</uri>
                            <bundleFileName>search-index.war</bundleFileName>
                            <contextRoot>/SearchIndex</contextRoot>
                        </webModule>
                    </modules>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>${artifactId}</artifactId>
                        <version>${project.version}</version>
                        <type>war</type>
                    </dependency>
                </dependencies>
            </plugin>

        </plugins>
    </build>

    <dependencies>  
        ...
    </dependencies>

</project>

我得到错误:

Artifact[war:myproject:se-index-webapp] is not a dependency of the project

我正在尝试做的事情可能吗?

4

1 回答 1

0

您必须更改的第一件事是根据 Maven 约定拥有一个单独的 EAR 模块,这会导致以下结构:

  +-- root (pom.xml)
       +--- mod-ear (pom.xml) packaging: ear
       +--- mod-war (pom.xml) packaging: war

你可以通过给出非常简单的方式定义对你的 mod-war 模块的依赖关系

   <dependencies>
      <dependency>
          <groupId>..</groupId>
          <artifactId>..</artifactId>
          <version>..</version>
      </dependency>
   ...
  </dependencies> 

这种方法的优点是您将属于 ear 的信息和属于 ear 模块的信息分开了。

结果是您可以在根级别执行 mvn clean 包,或者执行 mvn install / deploy 将 war 和 ear 部署到您的存储库中。

于 2012-03-15T09:34:38.297 回答