javamavenmaven-ear-plugin

maven-ear-plugin contextRoot ignored


I've been using maven-ear-plugin to create ear bundle and generate application.xml with custom contextRoot (everything works fine). Now I want to create 2 ear bundles and deploy them under different context path, so I defined plugin with 2 executions. But for some reason, maven-ear-plugin ignores contextRoot property and in generated application.xml it is using artifactId instead of contextRoot in both ears (so they have same context-root "app-ui"). Here is my maven-ear-plugin definition:

<plugin>
    <artifactId>maven-ear-plugin</artifactId>
    <version>2.10</version>
    <executions>
        <execution>
            <id>app1</id>
            <phase>package</phase>
            <goals>
                <goal>ear</goal>
            </goals>
            <configuration>
                <finalName>app1</finalName>
                <modules>
                    <webModule>
                        <groupId>com.x.y</groupId>
                        <artifactId>app-ui</artifactId>
                        <contextRoot>/app1-ui</contextRoot>
                    </webModule>
                </modules>
            </configuration>
        </execution>
        <execution>
            <id>app2</id>
            <phase>package</phase>
            <goals>
                <goal>ear</goal>
            </goals>
            <configuration>
                <finalName>app2</finalName>
                <modules>
                    <webModule>
                        <groupId>com.x.y</groupId>
                        <artifactId>app-ui</artifactId>
                        <contextRoot>/app2-ui</contextRoot>
                    </webModule>
                </modules>
            </configuration>
        </execution>

Any suggestions please?


Solution

  • The problem is that you generate the application.xml only once while you need two application.xml. For this you need to put also two executions of the generate-application-xml goal binded on the generate-resources phase of the maven lifecycle in order to generate the application.xml file two times (in two different folders preferably ^^) with two different configurations like this :

    <!-- first execution for the first application.xml in folder target/app1/META-INF -->
    <execution>
        <id>appxml-app1</id>
        <phase>generate-resources</phase>
        <goals>
            <goal>generate-application-xml</goal>
        </goals>
        <configuration>
            <generatedDescriptorLocation>target/app1/META-INF</generatedDescriptorLocation>
            <modules>
                <webModule>
                    <groupId>com.x.y</groupId>
                    <artifactId>app-ui</artifactId>
                    <contextRoot>/app1-ui</contextRoot>
                </webModule>
            </modules>
        </configuration>
    </execution>
    <!-- first execution for the generation of the ear with the application.xml in folder target/app1 -->
    <execution>
        <id>app1</id>
        <phase>package</phase>
        <goals>
            <goal>ear</goal>
        </goals>
        <configuration>
            <workDirectory>target/app1</workDirectory>
            <finalName>app1</finalName>
            <modules>
                <webModule>
                    <groupId>com.x.y</groupId>
                    <artifactId>app-ui</artifactId>
                </webModule>
            </modules>
        </configuration>
    </execution>
    
    <!-- second execution for the second application.xml in folder target/app2/META-INF -->
    <execution>
        <id>appxml-app2</id>
        <phase>generate-resources</phase>
        <goals>
            <goal>generate-application-xml</goal>
        </goals>
        <configuration>
            <generatedDescriptorLocation>target/app2/META-INF</generatedDescriptorLocation>
            <modules>
                <webModule>
                    <groupId>com.x.y</groupId>
                    <artifactId>app-ui</artifactId>
                    <contextRoot>/app2-ui</contextRoot>
                </webModule>
            </modules>
        </configuration>
    </execution>
    <!-- second execution for the generation of the ear with the application.xml in folder target/app2 -->
    <execution>
        <id>app2</id>
        <phase>package</phase>
        <goals>
            <goal>ear</goal>
        </goals>
        <configuration>
            <workDirectory>target/app2</workDirectory>
            <finalName>app2</finalName>
            <modules>
                <webModule>
                    <groupId>com.x.y</groupId>
                    <artifactId>app-ui</artifactId>
                </webModule>
            </modules>
        </configuration>
    </execution>
    

    To improve this, you can use variables to ensure that the folders will be the same for the two executions that concerns app1, etc, this is just a draft ;)