Tuesday, March 8, 2011

Starting H2 database

As of last, I'm using H2 database quite often and while opening a terminal and navigating to the `/bin` folder of H2 distribution is hardly a problem, it may become tedious after a while. So, without further, further, further, further... Damn it, here's the modified h2.sh with stuff taken from standard prologue of Racket scripts.
#!/bin/sh

# Remember current directory
saveD=`pwd`

# Find absolute path to this script,
# resolving symbolic references to the end
# (changes the current directory):
D=`dirname "$0"`
F=`basename "$0"`
cd "$D"
while test -L "$F"; do
  P=`readlink "$F"`
  D=`dirname "$P"`
  F=`basename "$P"`
  cd "$D"
done
D=`pwd`

cp=$D/h2-1.3.152.jar
if [ -n "$H2DRIVERS" ] ; then
  cp="$cp:$H2DRIVERS"
fi
if [ -n "$CLASSPATH" ] ; then
  cp="$cp:$CLASSPATH"
fi

cd $saveD
exec java -cp "$cp" org.h2.tools.Console $@

Now you just have to make a symbolic link to h2.sh (I called mine h2db) somewhere where your path is and make it executable. Yes, this assumes some kind of Unix.

No comments:

Post a Comment