使用shell脚本启动akka程序,参考于GearPump项目
准备工作:
便于测试修改,直接运行编译出的class来启动。在根目录下创建bin目录放shell脚本,创建lib放置依赖的jar包。安装JDK
脚本内容:
#!/bin/sh
if [ -z "$PROG_HOME" ] ; then
## resolve links - $0 may be a link to PROG_HOME
PRG="$0"
# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
saveddir=`pwd`
PROG_HOME=`dirname "$PRG"`/..
# make it fully qualified
PROG_HOME=`cd "$PROG_HOME" && pwd`
cd "$saveddir"
fi
#配置jdk目录
JAVACMD="/usr/jdk1.8.0_181/bin/java"
JAVA_HOME="/usr/jdk1.8.0_181/"
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly."
echo " We cannot execute $JAVACMD"
exit 1
fi
if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
CLASSPATH_SUFFIX=""
# Path separator used in EXTRA_CLASSPATH
PSEP=":"
echo $@
PROG_NAME=master
PROG_VERSION=0.8.5-SNAPSHOT
exec "$JAVACMD" \
"-server" "-Djava.net.preferIPv4Stack=true" "-DlogFilename=master" "-Djava.rmi.server.hostname=localhost" \
${JAVA_OPTS} \
-cp "${PROG_HOME}/conf${PSEP}${PROG_HOME}/lib/*${PSEP}${PROG_HOME}/target/scala-2.11/classes"\
com.mango.sharding.main.Master "$@"
启动脚本 根目录下 bin/XXX 可以带参数
例如 bin/master -ip 0.0.0.0 -port 0
在Master 中 处理参数
object Master{
def main(args: Array[String]): Unit = {}
}
// args: Array("-ip","0.0.0.0","-port","0")
- 注:把scala-library-X.X.X.jar放入\lib\