How to add WAR inside EAR with Maven

别来无恙 提交于 2019-12-17 17:39:09

问题


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?

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

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


回答1:


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

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>

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>

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

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.

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.




回答2:


Add WAR as dependency and use maven ear plugin. Then use ear:generate-application-xml goal and finally ear:ear goal.



来源:https://stackoverflow.com/questions/5167024/how-to-add-war-inside-ear-with-maven

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!