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. 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?

最佳回答

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.

问题回答

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.

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.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签