插件开发速度的使用



编辑

Downvester,这怎么是个糟糕的问题?我遇到这个问题是因为velocity需要类路径加载程序

想法是通过UI基于配置创建一个预定义的java类。创建了一个弹出UI以获取配置的Action。预定义的java自定义代码作为速度模板存储在插件资源中。当使用下面的代码加载模板时,它会抛出一个错误(资源未找到(

VelocityEngine velocityEngine = new VelocityEngine();
velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
velocityEngine.setProperty("runtime.log.logsystem.class","org.apache.velocity.runtime.log.NullLogSystem");
velocityEngine.init();
Template t = velocityEngine.getTemplate("EntityModel.vm");

使用以下方法来获得所需的结果。velocityevaluate接受velocityContext、velocityTemplate文件作为Reader,要编写输出,需要编写器。以下函数对于忽略任何环境中的资源加载器问题都很有用。

VelocityEngine velocityEngine = new VelocityEngine();
velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, new NullLogChute());
velocityEngine.init();
VelocityContext context = new VelocityContext();
context.put("fields",model.getFields());
context.put("vFunction",new VelocityFunction());
InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream("EntityModel.vm");
InputStreamReader inputStreamReader = new InputStreamReader(resourceAsStream);
velocityEngine.evaluate(context, writer, "ERROR", inputStreamReader);

最新更新