Using FitNesse with the Maven 2 classpath

When working with Maven 2 and FitNesse, it is desirable to use the Maven classpath in FitNesse. The FitNesse Maven plugin can do this for running tests in a build, but not for using FitNesse interactively.

While googling for a solution, the first hit that I got which addresses this problem is a blog by my fellow Xebian Erik Pragt. A drawback of his approach is that it does not handle transitive dependencies. Therefore, I found the need to write my own script. It uses a technology that is a little less groovy than what Erik used. But that did not stop me for wanting to share it with you, so here it is:

#!/bin/bash

CLASSPATH_PAGE=FitNesseRoot/MyTests/content.txt
echo "!contents" > $CLASSPATH_PAGE
echo >> $CLASSPATH_PAGE

# First add the output folder of the fitnesse project to the classpath
echo "!path target/classes"  >> $CLASSPATH_PAGE

# Then add the output folders of the other projects
for i in `ls ../*/target/classes | grep "target/classes:" | tr ":" " "`
do
    echo "!path ${i}" >> $CLASSPATH_PAGE
done
echo >> $CLASSPATH_PAGE

# Then output the jars on the maven classpath
mvn dependency:build-classpath | grep -v INFO | grep -v Downloading \
    | tr ":" "\n" | sed "s/^/-path /" | sed "s/.*\.m2\/repository/!path \${MAVEN_REPO}/" \
    >> $CLASSPATH_PAGE

Before using it, please note the following:

  • The script generates a page with classpath entries on a location specified by CLASSPATH_PAGE. You have to change the CLASSPATH_PAGE to your own page.
  • The generated classpath assumes that Java system property MAVEN_REPO is set. This can be done by updating the FitNesse run.sh script to include -DMAVEN_REPO=`echo ~/.m2/repository/`.

I tried to translate it to a Windows script but ran into the problem that the Maven classpath was bigger than the Windows limitation of 8192 characters. If you find a solution for this (other than using Cygwin), please share it!

Comments (2)

  1. Erik Pragt - Reply

    December 16, 2008 at 10:32 am

    Hi Marco,

    Nice solution! I fixed the transitive dependencies in my script by removing the script, and creating a Groovy Maven plugin for it. I never published it, since it was so small.

    Nice work. And for your classpath issue: how about dropping some dependencies??

    Erik

Add a Comment