Use image/resources that are included with plugin

Jordan Packer November 10, 2015

I'm working on my plugin writing skills (I'm still a beginner), and right now I'm trying to do a very simple exercise where I display an image on a page. I know how to edit the velocity template to include the necessary HTML, however my main goal here is to use a local resource that I have included with the plugin source/JAR (as opposed to a publicly available image on the internet). I've read documentation, various posts in this forum, and more...... but I still can't get it to work. I always just get a broken image icon and the web traffic logs give a 404 saying it can't find the image at that URL (I've tried many different variations of the URL, but nothing seems to work).

Here's my atlassian-plugin.xml:

<?xml version="1.0" encoding="UTF-8"?>
<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.name}" plugins-version="2">
  <plugin-info>
    <description>${project.description}</description>
    <version>${project.version}</version>
    <vendor name="${project.organization.name}" url="${project.organization.url}"/>
    <param name="plugin-icon">images/pluginIcon.png</param>
    <param name="plugin-logo">images/pluginLogo.png</param>
  </plugin-info>

  <resource type="i18n" name="i18n" location="tutorial-jira-add-content-to-view-issue-screen"/>

  <web-resource key="tutorial-jira-add-content-to-view-issue-screen-resources" name="tutorial-jira-add-content-to-view-issue-screen Web Resources">
    <dependency>com.atlassian.auiplugin:ajs</dependency>
    <resource type="download" name="images/" location="images/"/>
    <context>tutorial-jira-add-content-to-view-issue-screen</context>
  </web-resource>

  <component-import key="applicationProperties" interface="com.atlassian.sal.api.ApplicationProperties"/>
  <web-panel name="DueDateIndicator" i18n-name-key="due-date-indicator.name" key="due-date-indicator" location="atl.jira.view.issue.left.context" weight="201">
    <description key="due-date-indicator.description">The DueDateIndicator Plugin</description>
    <context-provider class="com.example.plugins.tutorial.DueDateIndicator"/>
    <resource name="view" type="velocity" location="due-date-indicator.vm"/>
    <label key="due-date-indicator.title"/>
  </web-panel>
</atlassian-plugin>

And here's my velocity template:

<img src="$req.contextPath/download/resources/com.example.plugins.tutorial:tutorial-jira-add-content-to-view-issue-screen-resources/images/1.png">

And yes, before you ask, I do indeed have the images folder located at src/main/resources/images with the files that I want.

3 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Jordan Packer November 12, 2015

I've tried many different variations of the addon key, but nothing seems right...... I can't seem to find any documentation that clearly specifies where I can find my addon key. If it is just groupId.artifactId as you suggest, then technically my addon key is com.example.plugins.tutorial.tutorial-jira-add-content-to-view-issue-screen. I've tried that key, however, and I still can't get to my images...

0 votes
Volodymyr Krupach
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.
November 11, 2015

There are should not be any wonders here. Check that your addon key (i.e. groupId.artifactId) is "com.example.plugins.tutorial".

0 votes
Midori
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.
November 11, 2015

Jordan, check what is actual rendered output from you Velocity template.

  1. Check if the URL looks OK.
  2. Check what happens when you paste to the address bar of your browser. 
Jordan Packer November 12, 2015

I've taken a look at the actual rendered output, and you're right, the link isn't being generated correctly ($req.contextPath isn't turning into the actual context path). However, I've tried entering the supposedly correct URL directly into the address bar of my browser, and it still doesn't work. I know that something as simple as this shouldn't be so complicated, but it's been blocking my for weeks now....

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