我想在谷歌應用程序引擎上使用速度框架。我用一種主要方法編寫了一個小程序,並嘗試在本地運行它。我得到以下異常:速度框架谷歌應用程序引擎
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());
}
}
同一程序運行在一個正常的Eclipse項目完美的罰款。可能是什麼問題呢?
感謝carl ..他們剛剛錯過了它......它的工作完全適用於應用引擎 – Aadith 2010-01-06 17:47:55
好。您是否必須解決我讀到的日誌記錄問題,或者您是否設法使其正常工作? – 2010-01-06 18:06:58
事實上,我很想知道該解決方案僅供參考。 – 2010-01-06 18:50:18