1. 程式人生 > >nohup: failed to run command `java': No such file or directory解決

nohup: failed to run command `java': No such file or directory解決

 

程式裡遠端執行shell命令(nohup java -jar ...)的執行,後臺日誌報錯如下:

nohup: failed to run command `java': No such file or directory

原因:一般來說這個報錯說明伺服器執行不了"java"這個命令

解決:

1、檢查執行該shell的伺服器有沒有裝jdk

2、檢查執行該shell的伺服器的環境變數有沒有將JAVA_HOME/bin加入(目的是可以在linux任意位置執行java命令)

-----------------------------------------------------------------------------------------------------------------------------------------

坑的是:我檢查了linux環境,java安裝正確,環境變數也加了,把shell命令拿到遠端伺服器使用者下任意目錄執行也正常!!但是通過程式遠端呼叫該shell命令還是報如上錯誤

無奈我在程式裡執行 nohup java -jar ... 命令前,先執行了一把 source /etc/profile , 執行shell命令如下:

source /etc/profile; nohup java -jar ...

然後成功測試通過!!!