Java Ninja Chronicles By Norris Shelton

Things I learned in the pursuit of code

I never really understood the use of the bundleFileName in the maven-ear-plugin. Who looks inside the .ear anyway. Well, there is a reason it is there.

I had to set the finalName property in the build section of several Maven modules across several projects. I learned the hard way that Maven modules do not talk to each other. The maven-ear-plugin assumes that the name of the artifacts is the default name. If you use finalName to change the name of the artifact, it is not aware. It configures your ear, but the file that it points to for the ejb or war module will not be there. Doh!

Example of finalName usage in an ejb module:

    <build>
        <finalName>isgwebsupport</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-ejb-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <ejbVersion>3.0</ejbVersion>
                    <generateClient>true</generateClient>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

Example of finalName usage in a war module:

    <build>
        <finalName>isgwebsupport</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <!--
                        Needed for skinny war
                        http://maven.apache.org/plugins/maven-war-plugin/examples/skinny-wars.html
                    -->
                    <packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

So, if you set the finalName of an ejb module or a web module, you must also set the bundleFileName in the ear module.

NOTE: You must specify the file extension when you use bundleFileName.

Example of the usage of bundleFileName in an ear module:

    <build>
        <finalName>isgwebsupport</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-ear-plugin</artifactId>
                <version>2.7</version>
                <configuration>
                    <version>5</version>
                    <description>ISGWebSupport</description>
                    <displayName>ISGWebSupport</displayName>
                    <defaultLibBundleDir>/lib</defaultLibBundleDir>
                    <skinnyWars>true</skinnyWars>
                    <modules>
                         <webModule>
							<groupId>${project.groupId}</groupId>
                            <artifactId>websupport-war</artifactId>
                            <contextRoot>/giswebsupport</contextRoot>
							<bundleFileName>isgwebsupport.war</bundleFileName>
                        </webModule>
                        <ejbModule>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>websupport-ejb</artifactId>
                            <bundleFileName>isgwebsupport.jar</bundleFileName>
                        </ejbModule>
                    </modules>
                </configuration>
            </plugin>
        </plugins>
    </build>

Lesson learned.

January 18th, 2013

Posted In: Maven

Tags: , , , , , , , , , ,

6 Comments

  • Ed says:

    Yes! this worked. Great, thanks very much. I’ve had an embedded WAR within my EAR that I’ve been trying to rename. This did it for me.

  • Mark Leonard says:

    Is it possible to reference the value of finalName somehow (when specifying bundleFileName) ?

  • John says:

    Thanks. This is nice, but I tried to combine the uri element with the bundleFileName. It overrode the bundleFileName. For example:

    com.my.application
    my-application-war
    my-application.war
    my-application
    MyApplication

    generates a “war” file named my-application (without the war file extension).

    Any ideas?

  • John says:

    Okay. All of the xml got stripped from my previous comment. Never mind.

  • Vikash kumar says:

    What if I have multiple war module in project and package these with different name

    • sheltonn says:

      I think it would work the same. The war module is a different artifact. It probably doesn’t matter how many you have. Then you would have multiple elements.

Leave a Reply

Your email address will not be published. Required fields are marked *

LinkedIn Auto Publish Powered By : XYZScripts.com