Maven

These are just random notes in no particular order about using Maven 2

Installation

  • Download from here: http://maven.apache.org/download.html
  • Extract zip/tar.gz somewhere
  • Create MVN_HOME environment variable pointing to the extracted folder
  • Add $MVN_HOME/bin to the PATH environment variable

You should now be able to open up a console and enter the mvn command. You should see something like:
mvn
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] You must specify at least one goal. Try 'install'
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Fri Mar 30 01:50:01 CDT 2007
[INFO] Final Memory: 1M/2M
[INFO] ------------------------------------------------------------------------
This means Maven is properly installed!

Number One Tip If You Have Trouble After Upgrading To A New Version

Often the plugins in your local repo and be incompatible.

To be safe, clean out (delete) your local repository:

  • Windows c:\Documents and Settings\USERNAME\.m2\repository
  • Macintosh /Users/USERNAME/.m2/repository
  • Linux /home/USERNAME/.m2/repository

Delete 'em!

Tips for Generating a Decent Maven2 Site

Notes for work in progress on Generating Maven2 Site article

This is okay: http://maven.apache.org/guides/mini/guide-site.html
But I was left missing some things.

  • write a good description

Most important, you will want a file here:
/src/site/site.xml
Skins:

Here's a nice article on making your own (I won't go into that...):
how_to_build_skin_for_maven_2_site_plugin

  <skin>
    <groupId>org.apache.maven</groupId>
    <artifactId>maven-classic-skin</artifactId>
    <version>1.0</version>
  </skin>

  <skin>
    <groupId>org.apache.tapestry</groupId>
    <artifactId>maven-skin</artifactId>
    <version>1.1</version>
  </skin>

  <skin>
    <groupId>org.jvnet.maven-javanet-skin</groupId>
    <artifactId>maven-javanet-skin</artifactId>
    <version>1.0</version>
  </skin>

reports in pom.xml scm in pom.xml issue management in pom.xml

  • Deploy tips....

JSPC - JSP Compiler Plugin for Webapps

I like to test that all JSP's are properly formed during the build/test cycle. You can use the jspc-maven-plugin to easily test this. If there is a JSP compilation problem, the build will fail. I don't typically deploy pre-compiled JSPs, so to achieve this "test but don't deploy" scenario, the important configuration to add is includeInProject and set it to false. An example of this is shown below. The following snippet goes in the the build/plugins section of your pom.xml for a webapp project:

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jspc-maven-plugin</artifactId>
        <configuration>
          <!--
             THE LINE BELOW ENSURES THAT THE
             COMPILED JSPs ARE NOT DEPLOYED
             TO THE WAR FILE 
          -->
          <includeInProject>false</includeInProject>
          <warSourceDirectory>${basedir}/src/webapp</warSourceDirectory>
          <workingDirectory>${basedir}/target</workingDirectory>
          <packageName></packageName>
        </configuration>
        <executions>
          <execution>
          <id>jspc</id>
          <goals>
            <goal>compile</goal>
          </goals>
          </execution>
        </executions>
      </plugin>

Roll Up Javadocs to Root Project in Multi-Component Project...

<project>

  ...

  <reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <configuration>
          <aggregate>true</aggregate>
          <maxmemory>256m</maxmemory>
        </configuration>
      </plugin>

      ...

    </plugins>
  </reporting>
</project>
I wish you could easily aggregate the unit test (surefire) reports :(

Run Tomcat Directly from a Maven Webapp Project

In Tomcat conf/server.xml within the <host> section:

<Context path="/CONTEXT-TO-EXPOSE-APP" 
         reloadable="true" 
         docBase="PROJECT_ROOT_DIR\target\PROJECT_ARTIFACT_NAME" 
         workDir="PROJECT_ROOT_DIR\target\work" />

Generate Eclipse Project Files (Including Sources)

mvn eclipse:eclipse -DdownloadSources=true