Unable to find velocity template resources

后端 未结 12 1133
星月不相逢
星月不相逢 2020-11-29 20:11

Just a simple velocity standalone app based on maven structure. Here is the code snippet written in Scala to render the template helloworld.vm in ${basedi

12条回答
  •  广开言路
    2020-11-29 20:35

    I put my .vm under the src/main/resources/templates, then the code is :

    Properties p = new Properties();
    p.setProperty("resource.loader", "class");
    p.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
    Velocity.init( p );       
    VelocityContext context = new VelocityContext();           
    Template template = Velocity.getTemplate("templates/my.vm");
    

    this works in web project.

    In eclipse Velocity.getTemplate("my.vm") works since velocity will look for the .vm file in src/main/resources/ or src/main/resources/templates, but in web project, we have to use Velocity.getTemplate("templates/my.vm");

提交回复
热议问题