2016-08-31 165 views
1

我想設置一個執行一個shell文件的cronjob(cPanel),它將運行java應用程序。但是我無法獲得班級路徑的工作。用cronjob運行JAVA的Linux命令

JAVA文件夾應用程序路徑

/home/user/public_html/version_1/data/downloader 

sh文件內這個命令通過終端與JAVA應用文件夾內

java -cp .:download.jar:log4j.jar:commons-httpclient.jar:commons-fileupload.jar:commons-logging.jar:commons-codec.jar:JAxe-1.0.jar portal.client.Main login 

然而運行它好好嘗試的文件夾之外運行時,當工作工作並返回以下錯誤

Error: Could not find or load main class portal.client.Main 

所以我嘗試具體的類路徑

java -cp /home/user/public_html/version_1/data/downloader/*:.download.jar:log4j.jar:commons-httpclient.jar:commons-fileupload.jar:commons-logging.jar:commons-codec.jar:JAxe-1.0.jar th.or.set.portal.client.Main login 

它仍然呈現

log4j:ERROR Could not read configuration file [log4j.properties]. 
java.io.FileNotFoundException: log4j.properties (No such file or directory) 
    at java.io.FileInputStream.open(Native Method) 
    at java.io.FileInputStream.<init>(FileInputStream.java:146) 
    at java.io.FileInputStream.<init>(FileInputStream.java:101) 
    at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:297) 
    at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:315) 
    at portal.client.Main.main(Main.java:32) 
log4j:ERROR Ignoring configuration file [log4j.properties]. 
log4j:WARN No appenders could be found for logger (portal.controller.MainController). 
log4j:WARN Please initialize the log4j system properly. 
Exception in thread "main" java.lang.IllegalArgumentException: InputStream cannot be null 
    at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:117) 
    at portal.client.DownloadParameter.parseLoginParam(DownloadParameter.java:177) 
    at portal.controller.MainController.execute(MainController.java:45) 
    at portal.client.Main.main(Main.java:130) 
+1

你在一個錯誤的目錄 – Jens

+0

顯示運行代碼在'portal.client.DownloadParameter.parseLoginParam(DownloadParameter.java:177)'' – talex

回答

2

嘛錯誤。您需要更改workdir。你可以簡單地通過使用cd

cd /home/user/public_html/version_1/data/downloader/ 
java -cp .:download.jar:log4j.jar:commons-httpclient.jar:commons-fileupload.jar:commons-logging.jar:commons-codec.jar:JAxe-1.0.jar portal.client.Main login 
-1

您是否嘗試創建一個腳本來設置你的環境,然後解僱你的java程序做呢?

你的腳本看起來是這樣的:

#!/bin/sh 
export CLASSPATH=<paths to files> 
java <your program> 

可以刪除你的腳本放到crontab中,然後和你一樣喜歡它玩弄,而無需更改您的內容。

+0

'附近的代碼如何幫助修復在當前目錄中被serced文件的問題不存在? – talex

+0

它有幫助,因爲它允許修改腳本,而不必一直與crontab混淆 – djb

-1

您可以設置類路徑中的jar包的清單文件

Manifest-Version: 1.0 
Implementation-Title: myapp 
Implementation-Version: 1.0.1 
Class-Path: lib/dep1.jar lib/dep2.jar 

,那麼你可以不經過任何額外的參數運行jar文件

+0

它不會修復當前目錄中搜索到的文件的問題沒有找到? – talex

+0

@talex爲什麼在類路徑中設置log4j.properties的路徑不會修復問題? – Amir

+0

因爲主要問題是「線程中的異常」main「java.lang.IllegalArgumentException:InputStream不能爲null」,我懷疑這是錯誤的文件路徑。 – talex