Created
February 20, 2012 03:33
-
-
Save mslinn/1867617 to your computer and use it in GitHub Desktop.
Bulletproof Scala REPL that works on all platforms with bash and includes current project classes like SBT console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Author Mike Slinn | |
# | |
# Requires JAVA_HOME to be set | |
# | |
# Invoke scalac with latest Scala 2.9.1 and Akka 2.0 jars, and Include SBT/Maven compiled project | |
# classes if invoked from root of an SBT/Maven project | |
# Does not use SBT or scala scripts, so this actually works on all platforms that have bash, | |
# including Mac, Linux and Cygwin. | |
# Invoke scala as usual with all options except classpath. | |
# Enter REPL as usual without any args: | |
# scala | |
# You can add to the classpath with -cp, if that option is provided first: | |
# scala -cp org.apache.httpcomponents/httpclient/jars/ | |
# The additions to the classpath are assumed to exist in the ~.ivy2/cache and must end with /jars/ | |
# The latest jar in that directory will be used | |
# See the final few entries to learn how to add arbitrary jars to the classpath | |
if [ $OSTYPE == cygwin ]; then | |
DELIM=";" | |
DHOME=`cygpath -dmas "$HOMEDRIVE$HOMEPATH"` | |
IVY=$DHOME/.ivy2/cache | |
else | |
IVY=~/.ivy2/cache | |
DELIM=: | |
fi | |
function D { | |
if [ "$CP" != "" ]; then | |
echo "$DELIM" | |
else | |
echo "" | |
fi | |
} | |
# Only includes jars in the classpath that exist in the local .ivy2 repo | |
function newest { | |
if [ -d "$IVY/${1}" ]; then | |
for f in $(ls -1t $IVY/${1}*.jar); do JAR=$f; done | |
if [ -f "$JAR" ]; then echo "$(D)$JAR"; fi | |
fi | |
} | |
# Include SBT/Maven compiled project classes if invoked from root of project | |
if [ -d target/scala-2.9.1/classes ]; then | |
CP=target/scala-2.9.1/classes | |
fi | |
# getopts is broken under cygwin :( | |
while [ "$1" == -cp ]; do | |
shift | |
CP=$CP$(D)$(newest $1) | |
shift | |
done | |
CP=$CP$(newest org.fusesource.jansi/jansi/jars/) | |
CP=$CP$(newest com.typesafe.akka/akka-actor/jars/) | |
CP=$CP$(newest org.scala-lang/scala-library/jars/) | |
CP=$CP$(newest com.github.scala-incubator.io/scala-io-core_2.9.1/jars/) | |
CP=$CP$(newest com.github.scala-incubator.io/scala-io-file_2.9.1/jars/) | |
CP=$CP$(newest org.scala-tools/scala-stm_2.9.1/jars/) | |
CP=$CP$(newest org.scala-lang/jline/jars/) | |
CP=$CP$(newest org.scala-lang/scala-compiler/jars/) | |
CP=$CP$(newest org.scala-lang/scala-library/jars/) | |
CP=$CP$(newest org.scala-lang/scalap/jars/) | |
CP=$CP$(newest commons-codec/commons-cli/jars/) | |
CP=$CP$(newest commons-codec/commons-codec/jars/) | |
CP=$CP$(newest commons-io/commons-io/jars/) | |
CP=$CP$(newest commons-logging/commons-logging/jars/) | |
CP=$CP$(newest commons-management/commons-management/jars/) | |
CP=$CP$(newest commons-pool/commons-pool/jars/) | |
CP=$CP$(newest org.multiverse/multiverse-alpha/jars/) | |
# not sure of the paths for these, so using original typesafe versions | |
CP=$CP$(D)/opt/typesafe-stack/lib/scala-swing.jar | |
CP=$CP$(D)/opt/typesafe-stack/lib/scala-dbc.jar | |
CP=$CP$(D)resources/application.conf | |
if [ "$VERBOSE" ]; then echo $CP; fi | |
JAVA_OPTS="-Xmx256M -Xms32M" | |
"$JAVA_HOME/bin/java" \ | |
$JAVA_OPTS \ | |
-Dscala.usejavacp=true -Dscala.home=/opt/typesafe-stack -Denv.emacs= \ | |
-Xbootclasspath/a:$CP \ | |
scala.tools.nsc.MainGenericRunner "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment