Unable to find velocity template resources

后端 未结 12 1098
星月不相逢
星月不相逢 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:31

    VelocityEngine velocityEngin = new VelocityEngine();
    velocityEngin.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    velocityEngin.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
    
    velocityEngin.init();
    
    Template template = velocityEngin.getTemplate("nameOfTheTemplateFile.vtl");
    

    you could use the above code to set the properties for velocity template. You can then give the name of the tempalte file when initializing the Template and it will find if it exists in the classpath.

    All the above classes come from package org.apache.velocity*

提交回复
热议问题