如何使用 Maven 在 EAR 中添加 WAR [英] How to add WAR inside EAR with Maven

查看:66
本文介绍了如何使用 Maven 在 EAR 中添加 WAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有应用程序的 EAR,我需要使用我自己打包为 WAR 的代码来扩展这个应用程序.是否有 maven 插件可以帮助我将 WAR 放入 EAR 中?

I have EAR with an application and I need to extend this app with my own code that is packaged as a WAR. Is there a maven plugin that can help me with putting the WAR inside the EAR?

手动过程是将 WAR 放入 EAR 并将模块添加到 application.xml.我想自动化.

The manual procedure is to put WAR inside EAR and add module to application.xml. I would like to automate that.

小说明 - WAR 项目正在使用 maven,但对于 EAR,我只有二进制文件.

small clarification - the WAR project is using maven but for EAR I have only the binary file nothing more.

推荐答案

我将创建一个具有 <packaging>ear</packaging> 的新模块.

I'd create a new module that has <packaging>ear</packaging>.

在这个 ear 模块的依赖项中,包含你的 war 模块:

In the dependencies for this ear module, include your war module:

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

现在在这个ear模块的构建插件中,包括maven-ear-plugin,例如:

Now in the build plugins for this ear module, include the maven-ear-plugin like, e.g.:

<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>
</plugin>

您可以根据需要更改 webModule 的特定配置值.

You can change the specific configuration values for the webModule as required.

现在创建一个父模块(使用pom)并将war模块和ear模块添加到其中.确保您正确设置了 war 和 ear 模块的 .

Now create a parent module (with <packaging>pom</packaging>) and add the war module and the ear module to it. Make sure you set the <parent> of the war and ear modules corrently.

当你为这个新的父级运行 mvn package 时,war 模块将构建一个 war 文件,ear 模块将构建一个 ear 文件(包含 war).

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.

这篇关于如何使用 Maven 在 EAR 中添加 WAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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