前言
從日志的報錯信息可以看出, /Library/Internet
大概率是因為系統(tǒng)安裝的jdk
路徑包含空格導(dǎo)致腳本啟動失敗
為什么能看出來是
jdk
路徑的問題, 那是因為遇到這種問題多了, 基本上也知道哪里會問題
特別是因為中間升級了mac
的系統(tǒng), 那各種問題都有, 都想回退系統(tǒng)版本了
解決辦法
一. 改系統(tǒng)配置文件
1. 系統(tǒng)配置: /etc/profile
- 能改, 但對于高版本的
mac
系統(tǒng), 改了也生效不了, 除非一些特別的操作, 個人覺得風(fēng)險太大, 沒有繼續(xù)嘗試
2. 用戶配置: ~/.bash_profile
- 使用
vim
命令打開~/.bash_profile
, 在文件最后, 添加如下內(nèi)容
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home
export PATH=$PATH:$JAVA_HOME/bin
- 讓改動生效(命令):
source ~/.bash_profile
查詢自己mac安裝的各類jdk路徑
/usr/libexec/java_home -V
-bash-3.2$ /usr/libexec/java_home -V Matching Java Virtual Machines (5): 13.0.2 (x86_64) "Oracle Corporation" - "Java SE 13.0.2" /Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home 11.0.7 (x86_64) "Oracle Corporation" - "Java SE 11.0.7" /Library/Java/JavaVirtualMachines/jdk-11.0.7.jdk/Contents/Home 1.8.301.09 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home 1.8.0_301 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home 1.8.0_221 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
二. 改啟動腳本
1. 指定腳本的jdk
路徑
- 從報錯提示, 確實需要修改的啟動腳本:
runserver.sh
- 使用命令
/usr/libexec/java_home -V
查詢當(dāng)前mac
已安裝的jdk
路徑
-bash-3.2$ /usr/libexec/java_home -V
Matching Java Virtual Machines (5):
13.0.2 (x86_64) "Oracle Corporation" - "Java SE 13.0.2" /Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home
11.0.7 (x86_64) "Oracle Corporation" - "Java SE 11.0.7" /Library/Java/JavaVirtualMachines/jdk-11.0.7.jdk/Contents/Home
1.8.301.09 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
1.8.0_301 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home
1.8.0_221 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
我選擇的版本是1.8
路徑是:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home
- 使用命令
vim {$path}/runserver.sh
({$path}
表示腳本所在的目錄/路徑 ) - 參考下面代碼, 將
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home
添加到啟動腳本里
#===========================================================================================
# Java Environment Setting
#===========================================================================================
error_exit ()
{
echo "ERROR: $1 !!"
exit 1
}
[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=$HOME/jdk/java
[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/java
[ ! -e "$JAVA_HOME/bin/java" ] && error_exit "Please set the JAVA_HOME variable in your environment, We need java(x64)!"
# force set java_home
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home
# force set java_home
export JAVA="$JAVA_HOME/bin/java"
export BASE_DIR=$(dirname $0)/..
export CLASSPATH=.:${BASE_DIR}/conf:${CLASSPATH}
- 保存并退出
:wq
, 重啟 RocketMQ 即可
參考來源
本文摘自 :https://www.cnblogs.com/