Usage of velocity for plugin development
Answered
Idea is to create a predefined class based on configuration through UI.
Created an Action which pops up UI to get the configuration.
The predefined custom code is stored as a velocity template inside plugin resources.
While using below code to load template it throws error (Resource Not found)
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");
Please sign in to leave a comment.
I'm sorry, I don't understand your question.
If you get the Resource Not found error message, you probably should revise your path.
@Jakub Chrzanowski
I'm trying to load a template that is in the plugin resources.
Placed the velocity template in the resources. While executing the plugin the velocity engine not able to load the resources.
(Note) Executing the code with the main function it works but not when it is ex ecuted as the plugin.
Guessing that there might be an issue with ( ClassLoader / ResourceLoader ) of velocity code while using it with the IntelliJ plugin code.
Thanks for the response.
I'm having a similar issue - the velocity classpathresourceloader does not find the resources directory on the classpath. I can work around this by loading the template as a string directly, eg:
But I cannot use, eg, the #parse directive if I do this
Lordfoom
Used below function it worked for me. hope it helps you. :)
Thanks Vigneshj6 - that is helpful. The only problem is it means you can't use #parse or #include directives in the template files. Very frustating.