goovy.sh かっこわるいけど、とりあえず
2007/09/20
2008/01/20
classpath
groovy
shell
Groovy - Running
groovy.lang.GroovyShell
にファイルをわたせればよいのですね。
前半部分は、groovyにあったコードを拝借。
#!/bin/sh
# Determine the Java command to use to start the JVM.
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD="java"
fi
fi
if [ ! -x "$JAVACMD" ] ; then
die "JAVA_HOME is not defined correctly, can not execute: $JAVACMD"
fi
if [ -z "$JAVA_HOME" ] ; then
warn "JAVA_HOME environment variable is not set"
fi
export CLASSPATH="$JAVA_HOME"/lib/tools.jar
#echo $0
R=`cd ..;pwd`"/lib"
#echo $R
export TARGET_DIR=$R
if [ -d "$TARGET_DIR" ]; then
for i in "$TARGET_DIR"/*.jar; do
CLASSPATH="$CLASSPATH":"$i"
done
fi
export CLASSPATH=$CLASSPATH
STARTER_MAIN_CLASS=groovy.lang.GroovyShell
CLASS=$1
shift
echo $CLASS
exec "$JAVACMD" $JAVA_OPTS \
-classpath "$CLASSPATH" \
$STARTER_MAIN_CLASS \
$CLASS \
"$@"
#echo $CLASSPATH
# Determine the Java command to use to start the JVM.
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD="java"
fi
fi
if [ ! -x "$JAVACMD" ] ; then
die "JAVA_HOME is not defined correctly, can not execute: $JAVACMD"
fi
if [ -z "$JAVA_HOME" ] ; then
warn "JAVA_HOME environment variable is not set"
fi
export CLASSPATH="$JAVA_HOME"/lib/tools.jar
#echo $0
R=`cd ..;pwd`"/lib"
#echo $R
export TARGET_DIR=$R
if [ -d "$TARGET_DIR" ]; then
for i in "$TARGET_DIR"/*.jar; do
CLASSPATH="$CLASSPATH":"$i"
done
fi
export CLASSPATH=$CLASSPATH
STARTER_MAIN_CLASS=groovy.lang.GroovyShell
CLASS=$1
shift
echo $CLASS
exec "$JAVACMD" $JAVA_OPTS \
-classpath "$CLASSPATH" \
$STARTER_MAIN_CLASS \
$CLASS \
"$@"
#echo $CLASSPATH
追記
この実装だと、bin以外のとこでうごかそうとするとだめですね。
下記のコードで修正
DIRNAME=`dirname "$0"`
R=`cd "$DIRNAME";cd ..;pwd`"/lib"
R=`cd "$DIRNAME";cd ..;pwd`"/lib"
: