2011-10-17 136 views
6

當instatiating速度我得到這個錯誤(貼只是 「引發的」 -messages):登錄錯誤在Linux系統上

java.lang.RuntimeException: Velocity could not be initialized! 
Caused by: org.apache.velocity.exception.VelocityException: Error initializing log: Failed to initialize an instance of org.apache.velocity.runtime.log.Log4JLogChute with the current runtime configuration. 
Caused by: org.apache.velocity.exception.VelocityException: Failed to initialize an instance of org.apache.velocity.runtime.log.Log4JLogChute with the current runtime configuration. 
Caused by: java.lang.RuntimeException: Error configuring Log4JLogChute : 
Caused by: java.io.FileNotFoundException: velocity.log (Permission denied) 

這是我的代碼片段:

VelocityEngine ve = new VelocityEngine(); 
    ve.evaluate(context, writer, "org.apache.velocity.runtime.log.NullLogChute", this.templateString); 

在首先我的代碼是這樣的:

runtimeServices = RuntimeSingleton.getRuntimeServices(); 
node = runtimeServices.parse(reader, templateName); 

在我的Windows機器能正常工作,但在Linux系統(Ubuntu的10.04),這是行不通的。這post並沒有多大幫助,因爲我還沒有找到任何線索哪些目錄我必須給寫權限。

我發現,下面的代碼是在Linux機器也工作:

String logPath = request.getRealPath("/velocity.log"); 
RuntimeSingleton.setProperty(RuntimeConstants.RUNTIME_LOG, logPath); 
runtimeServices = RuntimeSingleton.getRuntimeServices(); 
node = runtimeServices.parse(reader, templateName); 

這不是一個很好的解決方案,因爲我從來沒有肯定,如果我有我的真實背景下的寫入權限路徑。最好的情況是,關閉Velocity的日誌記錄。

我必須設置什麼不同的日誌記錄配置? NullLogChute只是不工作,或者我不適合使用它嗎?

在此先感謝!

回答

0

嗨問題是在寫權限的fs保護。 逸岸在堆棧跟蹤你:

java.io.FileNotFoundException: velocity.log (Permission denied) 

所以這是很好的東西決定在何處速度日誌將被寫入。 你說一句好話,你不知道在生產中你是否可以寫出一條特定路徑。 因此,最好在sysadmin可以根據自己的需要修改的屬性文件中放置該路徑。

因此,如果可以幫助您,請查看我對其他帖子的回覆。

鏈接here