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