使用插件开发速度

问题描述 投票:-1回答:1

编辑

下载者,这是一个坏问题吗?由于速度需要类路径加载器,因此我遇到了此问题

想法是基于通过UI的配置来创建预定义的Java类。创建了一个Action,该UI弹出UI以获取配置。预定义的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");
java velocity intellij-plugin
1个回答
0
投票

用于以下方法以达到所需的结果。速度评估接受速度上下文,vehicleTemplate文件作为读取器,并且要写入输出,需要写入器。下面的函数对于忽略任何环境中的资源加载器问题很有用。

        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);
© www.soinside.com 2019 - 2024. All rights reserved.