Search code examples
intellij-ideavelocityintellij-plugin

Registering a Template within an intellij Plugin


I have created my Apache Velocity template under /resources/fileTemplates/internal/myTemplateClass.vm and would like to use it through:

final JavaDirectoryServiceImpl javaDirectoryService = new JavaDirectoryServiceImpl();
javaDirectoryService.createClass(myPsiDirectory,
                                 "MyClassname",
                                 "myTemplateClass");

So I added the following in my plugin.xml:

  <extensions defaultExtensionNs="com.intellij">
    <!-- Add your extensions here -->
    <internalFileTemplate name="myTemplateClass"/>
  </extensions>

However when I run my plugin it claims that it did not find a template with the name "myTemplateClass". I assume it is cause I haven't linked to the file perse. Where should I link this?

Thanks


Solution

  • If you have an <internalFileTemplate> with the name of "myTemplateClass" and you want to use it to create a Java class, the template needs to be stored as fileTemplates/internal/myTemplateClass.java.ft. So you need to change the extension of your file.