繁体   English   中英

使用分类器创建一个WAR和一个包含该WAR作为一个模块的EAR?

[英]Maven creation of a WAR and an EAR containing that WAR as one module using classifier?

我了解这听起来可能是错误的事情,但是我试图做的是安装一个Maven POM(模块),该模块在安装时将打包为WAR,但此外,还打包为包含单个WAR的EAR。

需要说明的是:我希望将项目中的每个现有WAR打包在其自己的 EAR中。

我渴望得到支持的原因是因为我正在重新考虑打包已发布的WAR的方式,以便将每个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

我想做的事可能吗?

您需要更改的第一件事是基于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> 

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

结果是您可以在根级别执行mvn清洁程序包,也可以执行mvn安装/部署,从而将war和ear部署到存储库中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM