简体   繁体   English

谷歌应用引擎上的速度框架

[英]velocity framework on google app engine

i am trying to use velocity framework on google app engine. 我想在谷歌应用程序引擎上使用速度框架。 i wrote a small program with a main method and tried running it locally. 我用main方法编写了一个小程序,并尝试在本地运行它。 i get the following exception : 我得到以下异常:

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

Here is my program: 这是我的计划:

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() );    
 }
}

the same program runs perfectly fine on a normal eclipse project. 相同的程序在正常的eclipse项目上运行得非常好。 what could be the problem? 可能是什么问题呢?

Seems to only be the ServletLogChute class that requires the ServletContext , Velocity itself can work entirely standalone from a Servlet environment. 似乎只是需要ServletContextServletLogChute类,Velocity本身可以完全独立于Servlet环境工作。

Since you obviously don't have a servelt log, try adding the following before you call ve.init() : 由于您显然没有servelt日志,请在调用ve.init()之前尝试添加以下内容:

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

...or check here if you have specific logging requirements . ...或者如果您有特定的记录要求,请在此处查看

This may not be the end of the world and story, but there's a list of GAE compatible software: 这可能不是世界和故事的结束,但有一个GAE兼容软件列表:

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

and I didn't find Velocity in it. 我没有找到Velocity。 It's possible people just forgot to test and include it in the list, but it's also possible Velocity brings some API with it that doesn't play nicely with GAE. 人们可能只是忘记测试并将其包含在列表中,但也有可能Velocity带来了一些与GAE不能很好地兼容的API。

Velocity can be definitively made to run on GAE/J. 速度可以明确地在GAE / J上运行。

Apache Click Framework that is using Velocity as it's template engine, works without a problem on GAE/J. Apache Click Framework使用Velocity作为模板引擎,在GAE / J上没有问题。

It needs of course a different configuration than usual since GAE/J is a constraint environment, but nevertheless, it works. 它当然需要与平常不同的配置 ,因为GAE / J是一个约束环境,但它仍然有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM