Maven build war modules into an ear

1.4k views Asked by At

I have a maven project with ear packaging, including two webModule and dependencies to maven WAR package. Whenever I build changes, I need first to manually build the two war via "maven clean install" and in the end I build the ear always via "maven clean install".

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>it.test.esempio.fe</groupId>
        <artifactId>ESEMPIO_FE_PTL_PARENT</artifactId>
        <version>1.32.0-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent>
    <artifactId>ESEMPIO_FE_TEMA_COMPLETO</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>ear</packaging>
    <dependencies>
        <!-- START: PROJECT DEPENDENCIES -->
        <dependency>
            <groupId>it.test.esempio.fe</groupId>
            <artifactId>ESEMPIO_FE_TEMA_COMPLETO_STATICO</artifactId>
            <version>1.0.0-SNAPSHOT</version>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>it.test.esempio.fe</groupId>
            <artifactId>ESEMPIO_FE_TEMA_COMPLETO_DINAMICO</artifactId>
            <version>1.0.0-SNAPSHOT</version>
            <type>war</type>
        </dependency>
        <!-- END: PROJECT DEPENDENCIES -->
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-ear-plugin</artifactId>
                <version>2.10.1</version>
                <configuration>
                    <version>6</version>
                    <modules>
                        <webModule>
                            <groupId>it.test.esempio.fe</groupId>
                            <artifactId>ESEMPIO_FE_TEMA_COMPLETO_DINAMICO</artifactId>
                            <bundleFileName>ESEMPIO_FE_TEMA_COMPLETO_DINAMICO.war</bundleFileName>
                            <contextRoot>wps/ESEMPIO_FE_TEMA_COMPLETO_DINAMICO</contextRoot>
                        </webModule>
                        <webModule>
                            <groupId>it.test.esempio.fe</groupId>
                            <artifactId>ESEMPIO_FE_TEMA_COMPLETO_STATICO</artifactId>
                            <bundleFileName>ESEMPIO_FE_TEMA_COMPLETO_STATICO.war</bundleFileName>
                            <contextRoot>wps/ESEMPIO_FE_TEMA_COMPLETO_STATICO</contextRoot>
                        </webModule>
                    </modules>
                    <defaultLibBundleDir>lib</defaultLibBundleDir>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Is it possible to make in way to automatically build the 2 war and the ear with only one build command?

Thanks a lot

1

There are 1 answers

0
khmarbaise On

Create an appropriate directory structure:

 +-- root (pom.xml)
      +--- war-module1 (pom.xml)
      +--- war-module2 (pom.xml)
      +--- ear-module (pom.xml)

Put the list of existing modules into the root pom (modules list)..and define appropriate dependencies between the modules. Now you can simply build everything in one go from root via:

mvn clean package 

or if you need:

mvn clean install