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

Maven EJB MODULES

EJB modules are just like normal, but they also have an manifest section:

    <build>
        <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>
  • manifest – this section is responsible for generating the manifest file and adding the classpath entries

MAVEN WEB MODULES

Do everything like you normally would, except you will need a build section like the following:

    <build>
        <plugins>
            <plugin>
                <!--
                    Needed for skinny war
                    http://maven.apache.org/plugins/maven-war-plugin/examples/skinny-wars.html
                -->
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
  • packagingExcludes – tells the plugin to exclude the jar files from the lib directory
  • manifest – this section is responsible for generating the manifest file and adding the classpath entries

MAVEN EAR MODULE

<?xml version="1.0" encoding="UTF-8"?>
<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>com.appriss.justicexchange.licensemgr</groupId>
        <artifactId>licensemgr-parent</artifactId>
        <version>3.0-SNAPSHOT</version>
    </parent>

    <artifactId>licensemgr-ear</artifactId>
    <packaging>ear</packaging>

    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>licensemgr-ejb</artifactId>
            <version>${project.version}</version>
            <type>ejb</type>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>licensemgr-war</artifactId>
            <version>${project.version}</version>
            <type>war</type>
        </dependency>
        <!--
            Also include the war as a type=pom so that it pulls in the dependencies for inclusion in the ear /lib.
        -->
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>licensemgr-war</artifactId>
            <version>${project.version}</version>
            <type>pom</type>
        </dependency>
    </dependencies>

    <build>
        <finalName>licensemgr-${project.version}</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-ear-plugin</artifactId>
                <version>2.7</version>
                <configuration>
                    <version>5</version>
                    <displayName>ISG License Manager Application</displayName>
                    <description>LicenseManager</description>
                    <defaultLibBundleDir>/lib</defaultLibBundleDir>
                    <skinnyWars>true</skinnyWars>
                    <modules>
                        <ejbModule>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>licensemgr-ejb</artifactId>
                        </ejbModule>
                        <webModule>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>licensemgr-war</artifactId>
                            <contextRoot>licensemgr</contextRoot>
                            <bundleFileName>licensemgr-${project.version}.war</bundleFileName>
                        </webModule>
                    </modules>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

There should normally be a dependency entry for each module that will be packaged into the war. The EJB modules will be included with a of ejb and the WAR modules will be included with a of war. You ALSO need to add an extra dependency for each WAR module with a of pom. This will cause all of the dependencies to be pulled into the ear module and placed in the library bundle directory (/lib). If you don’t do this, you will need to duplicate each dependency of each war module as a dependency of the ear module.

The build section has 2 entries related to skinny wars:

  • defaultLibBundleDir – tells Maven where to bundle the jars
  • skinnyWars – tells Maven that you intend to make skinny wars

January 4th, 2013

Posted In: Java, Maven

Tags: , , , , , ,

3 Comments

WP to LinkedIn Auto Publish Powered By : XYZScripts.com