为了方便管理配置文件,每次更改配置文件(例如:jdbc.properties,service.properties),我们不需要重新build jar,所以将properties单独放到一个目录中,在liunx脚本调用java的过程中,我们将这些配置文件放到CLASSPATH中,并export。
#!/bin/bash
LIBRARY_PATH="$LIBRARY_PATH:/a/kycabinet/lib:/a/kyjava/lib"
export LANG="en_US.UTF-8"
export JAVA_HOME=/.../jdk
export LOGDIR=/a/b/c/log
export LOGFILE=$LOGDIR/test_$1_`date +"%Y%m%d-%H%M%S"`.log
export APP_MAIN=com.test.main.AppMain
cd /a/b/c/App
#the test_lib in the "/a/b/c/App" directory
for d in test_lib/*.jar;
do
CLASSPATH=${CLASSPATH}:"$d"
done
#the test_resources in the "/a/b/c/App" directory,we can put *.properties in the test_resources
for s in test_resources;
do
CLASSPATH=${CLASSPATH}:"$s"
done
export CLASSPATH LIBRARY_PATH
ps -ef | grep $APP_MAIN > Status_exec
num_exec=$(wc -l Status_exec | awk '{print $1}')
if [ $num_exec -gt 1 ]
then
echo "the app process is running"
exit 1
else
echo "";
fi
java -server -Xms5000m -Xmx20000m -cp $CLASSPATH $APP_MAIN $1 $2 > $LOGFILE