Using FitNesse with the Maven 2 classpath

16 Dec, 2008
Xebia Background Header Wave

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:

echo "!contents" > $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 ":" " "
    echo "!path ${i}" >> $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}/" \

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 script to include -DMAVEN_REPO=<code>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!


Get in touch with us to learn more about the subject and related solutions

Explore related posts