Velocity: Where to put the templates in a plugin project?

Pascal Charbonneau May 5, 2013

I am trying to use a velocity template for a simple configuration form for a plugin. According to dpcumentation and tutorials, placing the velocity template under the src/main/resources directory in of the maven project structure. This seemed to work when developping the plugin and it runs as expected via the SDK atlas-run but will not work when loading the plugin in my test JIRA instance.

In the test JIRA instance the plugin loads and work as expected but when trying to access the configuration serlvet, a "Content Encoding Error" shows instead. As per the log, it seems the TemplateRenderer cannot find the jirabot.vm template:

Caused by: org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'jirabot.vm'
	at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:483)
	at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:354)
	at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1400)
	at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1380)
	at org.apache.velocity.app.VelocityEngine.getTemplate(VelocityEngine.java:401)

Here are the relevant portions of the atlassian-plugin.xml:

<web-resource key="jirabot-resources" name="jirabot Web Resources">
    <dependency>com.atlassian.auiplugin:ajs</dependency>
    <resource type="download" name="jirabot.css" location="/css/jirabot.css"/>
    <resource type="download" name="jirabot.js" location="/js/jirabot.js"/>
    <resource type="download" name="images/" location="/images"/>
    <context>jirabot</context>
  </web-resource>

  <servlet name="botadmin" i18n-name-key="botadmin.name" key="botadmin" class="org.teamcascade.plugins.jirabot.servlet.BotAdminServlet">
    <description key="botadmin,description">IRC Bot Administration</description>
    <url-pattern>/botadmin</url-pattern>
  </servlet>

Anyone has any idea why the vlocity template can be found when running in the SDK and not in a live test instance of JIRA? Both the SDK run and the JIRA test instance are on version 5.2.8.

Thanks in advance

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Colin Goudie
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 5, 2013

If you have the velocity file under src/main/resources it should end up in the ROOT folder of the jar. Not under a resources directory

Colin Goudie
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 5, 2013

Maybe post your pom.xml might help

Pascal Charbonneau May 5, 2013

Colin: Thanks that should help locate the problem knowing where it should be to start with. I assume the SDK finds it because of the FastDev somehow. The only thing in the main directory of the JAR is the atlassian-plugin.xml at the moment it seems.

Pascal Charbonneau May 5, 2013

Colin: Thanks a lot for pointing me to my POM.xml. The error was caused by a <resource> filter in the <Build> section that was moving the .vm file to another location in the JAR. Just in case someone else is lazy like me and start a project based on another project POM hehe

Pralhad.Poul May 24, 2018

Can you elaborate more on what is wrong in pom.xml? Please.

0 votes
Pascal Charbonneau May 5, 2013

Colin: Thanks a lot for pointing me to my POM.xml. The error was caused by a <resource> filter in the <Build> section that was moving the .vm file to another location in the JAR. Just in case someone else is lazy like me and start a project based on another project POM:)

0 votes
David Pinn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 5, 2013

The error message "Content Encoding Error" makes me wonder whether the template is encoded in the way that Velocity expects. By default, Velocity expects templates to be encoded as "ISO-8859-1"; could it be that your template is encoded otherwise?

Pascal Charbonneau May 5, 2013

Colin: I just checked and the .vm file is in the jar under the resources/../ directory structure in the JAR. What really baffles me is that it runs fine with atlas-run. I use IDEA as an IDE usually to compile (in case there are known cavats) but even when trying to load the plugin jar generated by atlas-run I still get that error in the log. Is there any transformation done by the plugin loader (OSGi or otherwise) that would make a difference between the SDK run and an actual JIRA instance?

David: That was my first avenue of research but finally realized it wasnt loading the template at all when in the test instance.

0 votes
Colin Goudie
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 5, 2013

Is the .vm file definitely being added to the plugin jar file?

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events