<1># vi /etc/profile
<2>在最后加入以下几行:
export JAVA_HOME=/usr/java/jre1.6.0_45
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
===
如果是jre,则是如下几行:
export JAVA_HOME=/usr/java/jre1.6.0_45
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOMR/bin
<3># source /etc/profile 执行后生效
2.编写启动Java应用的shell脚本;
一个比较通用的脚本例子,该一下相关配置即可:
#!/bin/bash
#=======================================================================
# Mutable Properties
#=======================================================================
PROC_TAG="middleware_service"
VM_FLAG="-Xrs -Xms300M -Xmx758M -Ddefault.client.encoding=UTF-8 -Dfile.encoding=UTF-8 -Duser.language=Zh"
MAIN_CLASS="launcher.Launcher"
LOADER_PATH="../lib/**/*.jar ../ lib/*.jar ../ conf"
java_home=$JAVA_HOME
#java_home=/user
LOG_FILE=../logs/console.out
#=======================================================================
# Define information tag
#=======================================================================
RUNNING_TAG="[R]"
NOT_RUNNING_TAG="[X]"
ERROR_TAG="[E]"
INFO_TAG="[I]"
#=======================================================================
# Define functions for process
#=======================================================================
set_classpath(){
set ${LOADER_PATH}
while [ $# - gt 0 ]; do
classpath=${ classpath}:$1
shift
done
CLASSPATH=${ classpath}:${CLASSPATH}
}
is_proc_run(){
ps - ef | grep -w "${PROC_TAG}" | grep -v grep &>/ dev/null
return $?
}
status_proc(){
is_proc_run
if [ $? - eq 0 ]; then
echo "${RUNNING_TAG} ${PROC_TAG} is running !"
ps - ef | grep -w "${PROC_TAG}" | grep -v grep
set_classpath
${java_home}/bin/java - Diname=${PROC_TAG} ${VM_FLAG} -cp ${CLASSPATH} ${MAIN_CLASS} status
else
echo "${NOT_RUNNING_TAG} ${PROC_TAG} is not running !"
fi
}
start_proc(){
is_proc_run
if [ $? - eq 0 ]; then
echo "${INFO_TAG} ${PROC_TAG} is already running !"
else
echo "${INFO_TAG} Starting ${PROC_TAG} ..."
set_classpath
nohup ${java_home}/bin/java - Diname=${PROC_TAG} ${VM_FLAG} -cp ${CLASSPATH} ${MAIN_CLASS} start > ${LOG_FILE} 2>&1 &
sleep 1
is_proc_run
if [ $? - eq 0 ]; then
echo "${INFO_TAG} ${PROC_TAG} started !"
else
echo "${ERROR_TAG} ${PROC_TAG} starts failed !"
fi
fi
}
stop_proc(){
set_classpath
${java_home}/bin/java - Diname=${PROC_TAG} ${VM_FLAG} - cp ${CLASSPATH} ${MAIN_CLASS} stop
sleep 1
is_proc_run
if [ $? - eq 0 ]; then
pid=` ps - ef| grep " Boce"| grep -v grep | awk ‘{print $2}‘`
kill ${ pid}
fi
}
usage(){
echo ${PROC_DESC} usage:
echo -e "` basename $0` <start|stop|status|restart>"
echo -e "\ tstart - start ${PROC_TAG}"
echo -e "\ tstop - stop ${PROC_TAG}"
echo -e "\ tstatus - list ${PROC_TAG}"
echo -e "\ trestart - restart ${PROC_TAG}"
}
#=======================================================================
# Main Program begin
#=======================================================================
case $1 in
start)
start_proc
;;
status)
status_proc $2 $3
;;
stop)
stop_proc
;;
restart)
stop_proc
start_proc
;;
*)
usage
esac
3.部署运行相关的有用命令;
解压
tar -xf all.tar
删除
rm -rf xxx 强制删除文件和文件夹