1、环境变量配置
环境变量详细说明:
http://blog.oldboyedu.com/java-tomcat/
https://help.aliyun.com/document_detail/51376.html?spm=a2c4g.11186623.6.754.6Sdi1M
https://blog.csdn.net/zhangjing11292/article/details/51258187
https://blog.csdn.net/hehe524178933/article/details/50510178
jdk安装路径:
有的人安装在:
/usr/local/java/jdk
有的安装在:
/usr/java/jdk
所以export JAVA_HOME看安装java jdk的路径
可以是根据安装路径配置即可
export JAVA_HOME=/usr/local/java/jdk export JAVA_HOME=/usr/java/jdk
Java环境变量----只需要JRE
vi /etc/profile
环境变量配置1:wushuicheng
#set java environment export JAVA_HOME=/usr/java/jdk export JRE_HOME=$JAVA_HOME/jre export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
环境变量配置2:zhangyao,此配置有错误
#set java environment export JAVA_HOME=/usr/java/jdk export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
环境变量配置3:
#set java environment export JAVA_HOME=/usr/java/jdk1.8.0_141 export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib export PATH=$JAVA_HOME/bin:$PATH
生产场景环境变化配置4:oldboy&jingfeng推荐此环境变量配置
#set java environment export JAVA_HOME=/usr/java/jdk export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
source /etc/profile
2、如果是在shell脚本中执行java命令前要$JRE_HOME/bin/java
运行java命令用jre即可,最小化
shell脚本部分内容 #set java environment #export JAVA_HOME=/usr/local/java/jdk export JAVA_HOME=/usr/java/jdk export JRE_HOME=$JAVA_HOME/jre #执行java命令1: nohup $JRE_HOME/bin/java -Xms256m -Xmx512m -jar $JAR_NAME >/dev/null 2>&1 & #执行java命令1: $JRE_HOME/bin/java $JAVA_OPTS -jar -Dconf.path=file:conf/ $prog
脚本举例说明如下:
#!/bin/sh ## java env export JAVA_HOME=/usr/local/java/jdk1.7.0_72 export JRE_HOME=$JAVA_HOME/jre ## service name APP_NAME=user SERVICE_DIR=/home/wusc/edu/service/$APP_NAME SERVICE_NAME=edu-service-$APP_NAME JAR_NAME=$SERVICE_NAME\.jar PID=$SERVICE_NAME\.pid cd $SERVICE_DIR case "$1" in start) nohup $JRE_HOME/bin/java -Xms256m -Xmx512m -jar $JAR_NAME >/dev/null 2>&1 & echo $! > $SERVICE_DIR/$PID echo "=== start $SERVICE_NAME" ;; stop) kill `cat $SERVICE_DIR/$PID` rm -rf $SERVICE_DIR/$PID echo "=== stop $SERVICE_NAME" sleep 5 ## ## edu-service-aa.jar ## edu-service-aa-bb.jar P_ID=`ps -ef | grep -w "$SERVICE_NAME" | grep -v "grep" | awk '{print $2}'` if [ "$P_ID" == "" ]; then echo "=== $SERVICE_NAME process not exists or stop success" else echo "=== $SERVICE_NAME process pid is:$P_ID" echo "=== begin kill $SERVICE_NAME process, pid is:$P_ID" kill -9 $P_ID fi ;; restart) $0 stop sleep 2 $0 start echo "=== restart $SERVICE_NAME" ;; *) ## restart $0 stop sleep 2 $0 start ;; esac exit 0
转载于:https://blog.51cto.com/sandshell/2151521