Maven: A Look at the New Jive SBS 3.0 Archetypes

Version 5

    As you can see Maven: How To Create a New Maven Project, Jive has release its new SBS 3.0.0 platform.  To go along with that, we have also released our new Maven archetypes.  While the web overlay archetype is largely the same, the plugin archetype has changed considerably.  This document will cover those changes.

     

    Web Overlay

    The biggest change that you will notice for the web overlay archetype is in the Cargo settings, which changes the root web context from "clearspace" to "jive".

     

    <deployables>
        <deployable>
            <location>target/${customer.name}-${customer.version}-sbs-${sbs.version}.war</location>
            <pingURL>http://localhost:8080/jive</pingURL>
            <properties>
                <context>jive</context>
            </properties>
        </deployable>
    </deployables>
    

     

    This means simply that you will now use http://localhost:8080/jive to access your local instance.

     

     

    Plugin

    Rather than relying on the assembly approach, which allowed for a loosey-goosey plugin structure, we now rely on the Maven Plugin Packager, which dictates a specific layout for the plugin.  Said structure looks a little like this:

     

    Picture1.png

     

    src/main/java

    Your Java code goes here, same as always

     

    src/main/resources

    Your plugin config files go here.  When the plugin is compiled, all files (this is configurable in the pom) in this directory will be pushed to the classes directory, except for the following:

    • cache-config.xml
    • plugin.xml
    • schema.xml
    • spring.xml
    • struts.xml

     

    src/main/scripts

    Put any custom Javascript here.  The scripts directory itself will be copied to the exploded plugin directory.

     

    src/main/web

    Put your Freemarker templates, CSS files, images, etc., here.  All files and directory contained within the web directory will be copied to the exploded plugin directory.  Note that the web directory itself will not be copied.

     

    What's happening in the POM?

    We have also changed how the pom looks, utilizing several new Maven plugins to get the job done without using Ant so much.  Allow me to take you on a little journey through our little POM.

     

    <resources>
      <resource>
        <directory>${basedir}/src/main/resources</directory>
        <excludes>
          <exclude>cache-config.xml</exclude>
          <exclude>plugin.xml</exclude>
          <exclude>schema.xml</exclude>
          <exclude>spring.xml</exclude>
          <exclude>struts.xml</exclude>
        </excludes>
      </resource>
    </resources>

    By definition, anything defined as a resource in the pom (src/main/resources in this case) will be sent to the classes directory when the plugin is build.  Here, we are specifying that the plugin configuration files should not be pushed to the classes directory.

     

    maven-dependency-plugin

    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>aspectj-maven-plugin</artifactId>
      <version>1.1</version>
      <configuration>
        <aspectLibraries>
          <aspectLibrary>
            <groupId>com.jivesoftware</groupId>
            <artifactId>spring-aspects</artifactId>
          </aspectLibrary>
        </aspectLibraries>
        <source>1.5</source>
      </configuration>
      <executions>
        <execution>
          <goals>
            <goal>compile</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
    

    The Maven AspectJ plugin allows for the weaving of aspects into the SBS plugin code.  By default, it is configured to weave in aspects defined in Spring.

     

    maven-dependency-plugin

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <executions>
        <execution>
          <id>copy-extra-dependencies</id>
          <goals>
            <goal>copy-dependencies</goal>
          </goals>
          <configuration>
            <excludeScope>
              provided
            </excludeScope>
          </configuration>
        </execution>
      </executions>
    </plugin>

    The Maven Dependency Plugin copies any external dependencies needed by your plugin, and copies them the target/dependency director.  The use of this plugin negates the need to physically include external JAR files in your plugin's codebase, and makes use of Maven dependencies.  Which dependencies are included depends upon the configuration of the plugin specified in the POM.  By default all dependencies that do not have a scope of provided are copied to the target/dependency directory.  See the Maven Dependency Plugin configuration documentation for more info.

     

     

    maven-clearspace-plugin-packager

    <plugin>
      <groupId>com.jivesoftware.maven</groupId>
      <artifactId>
           maven-clearspace-plugin-packager
      </artifactId>
      <version>2.1-SNAPSHOT</version>
      <executions>
        <execution>
          <goals>
            <goal>package-plugin</goal>
          </goals>
          <phase>package</phase>
        </execution>
      </executions>
    </plugin>

    This shows how we are utilizing the Plugin Packager Mojo during the package phase.  This mojo determines how all of the plugin resources are structured within the plugin JAR, and creates the plugin JAR file itself.

     

     

    maven-jar-plugin

    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
    <finalName>tmp-classes</finalName>
    </configuration>
    </plugin>

    We want to use the JAR created by the Plugin Packager mojo--not the one built my the core Maven JAR plugin.  So we reconfigure the core maven-jar-plugin to name its JAR something else that we delete later on.

     

     

    maven-antrun-plugin

    <plugin>
      <artifactId>maven-antrun-plugin</artifactId>
      <version>1.1</version>
      <executions>
        <execution>
          <id>rename-exploded</id>
          <goals>
            <goal>run</goal>
          </goals>
          <phase>package</phase>
          <configuration>
            <tasks>
              <delete file="target/tmp-classes*" />
            </tasks>
          </configuration>
        </execution>
      </executions>
    </plugin>

    Here we're using Ant to delete the JAR file created by the core maven-jar-plugin, since we want to use the one created by our mojo.

     

    maven-source-plugin

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-source-plugin</artifactId>
      <executions>
        <execution>
          <id>attach-sources</id>
          <phase>verify</phase>
          <goals>
            <goal>jar</goal>
          </goals>
        </execution>
      </executions>
    </plugin>

    Nothing special here, but it's new so I included it in the doc.  This creates a source jar for the plugin.

     

    jive-sbs dependencies

    <dependency>
      <groupId>com.jivesoftware</groupId>
      <artifactId>jive-sbs-employee</artifactId>     <!-- was clearspacex -->
      <version>${sbs.version}</version>
      <type>jar</type>
      <scope>provided</scope>
    </dependency>
          
    <dependency>
      <groupId>com.jivesoftware</groupId>
      <artifactId>jive-sbs-employee-all</artifactId> <!-- was clearspacex-all -->

      <version>${sbs.version}</version>
      <type>pom</type>
      <scope>provided</scope>
    </dependency>

    These dependencies are our new best friends.  Note that there is no longer any distiction between internal and external versions of SBS with respect to Maven dependencies.