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

查看:514
本文介绍了如何使用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>

现在在这个耳模块的构建插件中,包括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的具体配置值根据需要。

现在创建一个父模块(< packaging> pom< / packaging> )并将war模块和ear模块添加到其中。确保正确设置war和ear模块的< parent>

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文件(包含war)将由ear模块构建。

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天全站免登陆