Action may not always bring happiness, but there is no happiness without action. 行动不一定带来幸福,不行动就肯定没有幸福。
在linux中,使用java命令并指定classpath方式运行jar包:
#!/bin/sh
RUN_HOME=/home/a/b
db_config=$RUN_HOME/dbconfig
app_lib_path=$RUN_HOME/abc.jar
#将CLASSPATH初始化为空
CLASSPATH=
#迭代某个目录将这个jar的依赖包也放入CLASSPATH中
for d in ${RUN_HOME}/libs/*.jar;
do
CLASSPATH=${CLASSPATH}:"$d"
done
CLASSPATH=$CLASSPATH:$db_config:$app_lib_path
echo "classpath is ---"$CLASSPATH;
LOGFILE=$RUN_HOME/logs/abc-`date +"%Y%m%d-%H%M%S"`.log
JAVA_CMD=/usr/bin/java
main_class=q.c.d.Test
echo "start time is " `date`
nohup $JAVA_CMD -Xms2G -Xmx4G -classpath $CLASSPATH ${main_class} > $LOGFILE 2>&1 &
echo "Finished! end time is "+`date`
classpath直接包含某个jar的目录是没有作用的。
classpath参考:
http://docs.oracle.com/javase/tutorial/essential/environment/paths.html
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html
export的作用,将当前脚本的自定义变量变成环境变量,供子程序使用.
参考:http://linux.vbird.org/linux_basic/0320bash.php#export
与其抱怨玫瑰丛长满了刺,还不如感激刺丛里竟生出了玫瑰。 Action may not always bring happiness, but there is no happiness without action.