简体   繁体   English

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

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

I understand that this might sound like the wrong thing to do, but what I'm attempting is to have a Maven POM (module) that when installed will package as WAR but in addition, as an EAR that contains the single WAR. 我了解这听起来可能是错误的事情,但是我试图做的是安装一个Maven POM(模块),该模块在安装时将打包为WAR,但此外,还打包为包含单个WAR的EAR。

To clarify: I am looking to wrap each existing WAR in my project in its own EAR. 需要说明的是:我希望将项目中的每个现有WAR打包在其自己的 EAR中。

The reason behind my desire is because I am looking at restructuring the way we package our released WARs so that each is contained within an EAR (but also still generate an independent WAR artifact for development ease). 我渴望得到支持的原因是因为我正在重新考虑打包已发布的WAR的方式,以便将每个WAR包含在EAR中(但仍会生成独立的WAR工件以简化开发工作)。 I am not keen to create a new module that depends on the WAR and package it in an EAR because I have loads of WARs. 我不希望创建一个依赖WAR的新模块并将其打包到EAR中,因为我有很多WAR。

Currently I am trying this, for one of my existing WAR modules, without success using a classifier : 目前,对于我现有的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>

I get the error: 我得到错误:

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

Is what I'm trying to do possible? 我想做的事可能吗?

The first thing you have to change is based on Maven conventions to have a separate EAR module which results in the following structure: 您需要更改的第一件事是基于Maven约定,以拥有一个单独的EAR模块,该模块具有以下结构:

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

Than you can define the dependencies to your mod-war module very simple by giving 比您可以通过以下方式非常简单地定义对mod-war模块的依赖关系:

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

The advantage of this approach that you have separated the information which belong to ear and them which belong to ear module. 这种方法的优点是,您已将属于耳朵的信息和属于耳朵模块的信息分开了。

The result is you can do a mvn clean package on the root level or do a mvn install / deploy which deploys war as well as ear into your repository. 结果是您可以在根级别执行mvn清洁程序包,也可以执行mvn安装/部署,从而将war和ear部署到存储库中。

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

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