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

发布于 2024-08-16 23:41:32 字数 1920 浏览 3 评论 0原文

我正在尝试在谷歌应用程序引擎上使用速度框架。我编写了一个带有 main 方法的小程序,并尝试在本地运行它。我得到以下异常:

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 项目上运行得非常好。可能是什么问题?

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. 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. what could be the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

黎歌 2024-08-23 23:41:32

似乎只有 ServletLogChute 类需要 ServletContext ,Velocity 本身可以完全独立于 Servlet 环境工作。

由于您显然没有servlt日志,因此请尝试在调用ve.init()之前添加以下内容:

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

...或如果您有特定的日志记录要求,请在此处查看

Seems to only be the ServletLogChute class that requires the ServletContext, Velocity itself can work entirely standalone from a Servlet environment.

Since you obviously don't have a servelt log, try adding the following before you call ve.init():

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

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

黎歌 2024-08-23 23:41:32

这可能不是世界末日和故事,但有一个 GAE 兼容软件列表:

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

我没有在其中找到 Velocity。人们可能只是忘记测试并将其包含在列表中,但也有可能 Velocity 带来了一些与 GAE 不能很好地配合的 API。

This may not be the end of the world and story, but there's a list of GAE compatible software:

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

and I didn't find Velocity in it. 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.

悲喜皆因你 2024-08-23 23:41:32

Velocity 绝对可以在 GAE/J 上运行。

Apache Click 使用 Velocity 作为模板引擎的框架,在 GAE/J 上运行没有问题。

当然,它需要不同的配置< /a> 比平常多,因为 GAE/J 是一个约束环境,但它仍然有效。

Velocity can be definitively made to run on GAE/J.

Apache Click Framework that is using Velocity as it's template engine, works without a problem on GAE/J.

It needs of course a different configuration than usual since GAE/J is a constraint environment, but nevertheless, it works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文