January 15, 2010
filed mid-afternoon by DrScofield in: hacking
technorati tags:
QR code for this entry · average time to read 0:57 minutes

one thing i quite like about scala is that ability to run it in “interpreted” mode via the scala command. that allows me — similiar to python or ipython — to experiment and quickly try things out or even test my classes and objects.

what was a bit of a pain was getting the proper classpath constructed so that not only target/classes was picked up but also all the required dependencies. poking a bit around in maven’s plugin documentation i came across the dependency plugin and in particular the dependency:build-classpath mojo, armed with that information i came up with the following rather useful shell script:

#!/bin/bash
top=$(pwd)
cwd=$(pwd)
while  [ "$top" != "/" -a ! -e "$top/pom.xml" ] ; do
    cd ..
    top=$(pwd)
done
cd $cwd

if [ -e "$top/pom.xml" ] ; then
    cd $top

    echo "generating scala classpath based on maven pom.xml"
    mvn dependency:build-classpath -Dmdep.outputFile=.classpath-scala

    echo "starting scala"
    scala -cp target/classes:$(cat .classpath-scala)

else

    echo "cannot find top level pom.xml! must have taken a wrong turn somewhere. sorry."
    exit 1

fi

save under a convenient name, stir, and enjoy: call this script instead of calling scala directly.

all content posted on these pages is an expression of my own mind. my employer is welcome to share these opinions but then again he might not want to.

1 comment »

  1. and as has been pointed out to me, a simple

    $ mvn scala:console
    

    does the job as well! oh, well…

    comment by dirk husemann — January 18, 2010 @ 09:57

RSS feed for comments on this post. TrackBack URI

Leave a comment