2010-01-06 31 views
5

我想在谷歌應用程序引擎上使用速度框架。我用一種主要方法編寫了一個小程序,並嘗試在本地運行它。我得到以下異常:速度框架谷歌應用程序引擎

 
Exception in thread "main" org.apache.velocity.exception.VelocityException: Failed to initialize an instance of org.apache.velocity.runtime.log.ServletLogChute with the current runtime configuration. 
    at org.apache.velocity.runtime.log.LogManager.createLogChute(LogManager.java:206) 
    at org.apache.velocity.runtime.log.LogManager.updateLog(LogManager.java:255) 
    at org.apache.velocity.runtime.RuntimeInstance.initializeLog(RuntimeInstance.java:795) 
    at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:250) 
    at org.apache.velocity.app.VelocityEngine.init(VelocityEngine.java:107) 
    at Main.main(Main.java:10) 
Caused by: java.lang.UnsupportedOperationException: Could not retrieve ServletContext from application attributes 
    at org.apache.velocity.runtime.log.ServletLogChute.init(ServletLogChute.java:73) 
    at org.apache.velocity.runtime.log.LogManager.createLogChute(LogManager.java:157) 
    ... 5 more 

這裏是我的程序:

import java.io.StringWriter; 
import org.apache.velocity.app.VelocityEngine; 
import org.apache.velocity.Template; 
import org.apache.velocity.VelocityContext; 

public class Main { 
public static void main(String[] args) throws Exception{ 
     /* first, get and initialize an engine */ 
     VelocityEngine ve = new VelocityEngine(); 
     ve.init(); 
     /* next, get the Template */ 
     Template t = ve.getTemplate("helloworld.vm"); 
     /* create a context and add data */ 
     VelocityContext context = new VelocityContext(); 
     context.put("name", "World"); 
     /* now render the template into a StringWriter */ 
     StringWriter writer = new StringWriter(); 
     t.merge(context, writer); 
     /* show the World */ 
     System.out.println(writer.toString());  
} 
} 

同一程序運行在一個正常的Ec​​lipse項目完美的罰款。可能是什麼問題呢?

回答

9

似乎只有ServletLogChute類需要ServletContext,Velocity本身可以完全獨立於Servlet環境。

既然你明明沒有的servelt日誌,嘗試添加下面你叫ve.init()前:

ve.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogChute"); 

...或check here if you have specific logging requirements

2

這可能不是世界,故事的結局,但有GAE兼容軟件的列表:

http://groups.google.com/group/google-appengine-java/web/will-it-play-in-app-engine

,我沒有找到它的速度。人們可能忘記測試並將其包含在列表中,但Velocity也可能會帶來一些與GAE無法很好兼容的API。

+2

感謝carl ..他們剛剛錯過了它......它的工作完全適用於應用引擎 – Aadith 2010-01-06 17:47:55

+0

好。您是否必須解決我讀到的日誌記錄問題,或者您是否設法使其正常工作? – 2010-01-06 18:06:58

+0

事實上,我很想知道該解決方案僅供參考。 – 2010-01-06 18:50:18

2

速度可以確定地在GAE/J上運行。

使用Velocity作爲模板引擎的框架,在GAE/J上沒有問題。

因爲GAE/J是一個約束環境,所以它當然需要比平常的different configuration,但它仍然有效。