Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Can anyone please post their sample code of a small working gadget?

Jayashree Shetty
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.
April 15, 2014

I have tried the JIRA4 gadget from the Jtricks and also referred the cookbook. But the gadget doesnt seems to be working. It gets listed out in the addd-ons section but i cant find it in the gadget lists. No errors detected when i referred the log. Can anyone please post their sample code preferably zipped code of their working gadget which would be very helpful for me to implement a gadget on rest api.

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Jobin Kuruvilla [Adaptavist]
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.
April 25, 2014

Jayashree,

I finally got a chance to look and it works as expected. I have attached the code I used in the book as a plugin in the post now. In fact, you would get this code if you purchase the book from Packt!

Let us know if this works.

Jayashree Shetty
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.
April 28, 2014

Hi Jobin. I will download the gadget-extended-plugin.zip and try installing and see if it works for me. Thanks for the help. i will update you on this.

Jayashree Shetty
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.
April 28, 2014

Thanks Jobin it worked now.

Jobin Kuruvilla [Adaptavist]
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.
April 28, 2014

Great. Btw, there is no change in JIRA6. I just used the same code. Maybe you want to tell us what were you doing differently (so that it will help others if it is likely to be a common mistake) ;)

Jayashree Shetty
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.
April 29, 2014

Actually jobin i just ran your code. It was workign fine. I am planning to redo it keeping your code as reference, in case i end up with the same problem will surely post it :)

Jayashree Shetty
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 6, 2014

Hi Jobin, i did tried creating the plugin and i ended up getting the same error that its not able to access the resource file. What i found was in gadget.xml file in the

<Locale message ---- > the url was entered wrongly.

In this you will find i have used some dotted lines there i had to write groupid.artifactid. I missed this hence i was getting this error.

<Locale messages="__ATLASSIAN_BASE_URL__/download/resources/.........../i18n/messages.xml"/>

Now its working fine :)

Jobin Kuruvilla [Adaptavist]
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 6, 2014

Ah I see. Good to know!

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 15, 2014

There are a number of open-source gadgets in the marketplace. There's not a lot of point in asking for something that works because that will mean you aren't learning how to do it properly for yourself. Also, you haven't told us what version of Jira you are aiming for and that could well be the entire problem with what you've already got.

You've got something which is close too, so comparing it with a totally different set of code could well just confuse you even more - I'd suggest fixing what you've got, rather than taking wild swipes at new stuff.

Also, if your gadget is loading and appearing on the plugin list, you are very very close - I'd have a look at the Atlassian standard docs to see what you're doing differently from there

Jayashree Shetty
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.
April 15, 2014

Thanks Nic. I have followed the doc and have repeated this some 6-7 times. I am using the JIRA 6.0 version. i did check the docs but didnt get any help.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 15, 2014

So, which "how to build a gadget" docs are you following, and what are you doing differently from what they say?

Jayashree Shetty
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.
April 15, 2014

i am following http://www.j-tricks.com/1/post/2011/03/writing-jira4-gadgets.html. i am doing exactly the same way they have explained.

Jobin Kuruvilla [Adaptavist]
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.
April 15, 2014

Jayashree, it is most likely that something have changed in the latest versions. I haven't got a chance to look at it yet. I am hoping someone else will chime in but if not, I will take a look at it as soon as I can.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 15, 2014

So you're writing for Jira 4? If not, then that could be the problem. Stuff that works for 4 seems to translate up into Jira 5 ok, but I've had to fiddle with it a bit to make the code work in 6

Have a look at https://developer.atlassian.com/display/JIRADEV/Plugin+Tutorial+-+Writing+Gadgets+for+JIRAif you're writing for 4 or 5. If you're writing for 6, I found the best trick was to use the SDK to create an empty plugin, then migrate my code into it.

Jayashree Shetty
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.
April 22, 2014

I did try that but i get this error : Error occurred while retrieving gadget spec for rest/gadgets/1.0/g/com.atlassian.plugins.tutorial.jira-gadget-tutorial-plugin:tutorial-gadget/gadget.xml .

Can anyone please tel me how to resolve this issue. its very urgent.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 22, 2014

So what are you doing differently from the tutorial instructions?

Jayashree Shetty
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.
April 22, 2014

i didnt do anything different. i followed the instructions step by step. Some one has mentioned in the link below that the plugin doesnt seem to be working. I dont find the plugin when i click on " Add Gadget" option

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 22, 2014

You really do have to tell us more about what you're doing.

We don't know what versions you are working on, what your settings are or even what errors you're running into. Or why you're jumping around without explaining what or why.

The "Error retrieving gadget spec" sounds like you've compiled it all and got the development Jira running, which means you've got past all the problems mentioned in the comments and you have a structural problem with your code (because Jira can't find what you've told it to look for). Problem with that is that "I didn't do anything different" is not right, as the tutorial works fine for me. But I'm pretty sure I'm using different versions of everything for a start...

Jayashree Shetty
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.
April 23, 2014

As i have mentioned in the earlier comment of this post that i am using Jira Version 6.0. I guess may be that's the problem.

Jayashree Shetty
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.
April 23, 2014

Now i have installed JIRA 5.0 version and ran again the atlas-run command. i end up getting this error again

Error occurred while retrieving gadget spec for rest/gadgets/1.0/g/com.atlassian.plugins.tutorial.jira-gadget-tutorial-plugin:tutorial-gadget/gadget.xml

Also i can see another error just befor ethis error

Unable to find resource for plugin: jira-gadget-tutorial-plugin and path: i18n/ALL_ALL.xml

Although i have included a i18n folder and an xml file within it why is it unable to access the file?

JIRA version : 5.0

JDK version : 1.6

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 23, 2014

Ok, looking at the instructions for 5, I have used those a while ago to create a skeleton gadget that worked, so we go back to the question "what are you doing differently from the instructions".

Giving the original error message helps, rather than just "can not load" which could be just a result of other errors, or a genuine config error (If it were just that error, then it's usually in the plugin definition xml, but cannot load is also a result of other errors).

Short answer there is that your i8n file is in a different place to where you've told the plugin it is. You need to line the plugin xml up with where you've put the file.

Jayashree Shetty
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.
April 23, 2014

Thanks Nic for the help. I understand i am asking you a lot of questions. Since this is my first rest plugin i am very much eager to set this working. Regarding the i18n file it was my mistake as you have mentioned at the last 2 lines of your comment. However i have fixed that. But still i am unable to see the plugin when i click on "Add Gadgets"

These are the errors/info

[INFO] [talledLocalContainer] Apr 24, 2014 3:49:55 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate

[INFO] [talledLocalContainer] INFO: Initiating Jersey application, version 'Jersey: 1.8-atlassian-6 03/12/2012 02:59 PM'

[INFO] [talledLocalContainer] 2014-04-24 15:50:00,201 http-2990-7 INFO anonymous 950x431x2 - 14.99.99.234 /download/resources/jira-gadget-tutorial-plugin/i18n/ALL_ALL.xml [atlassian.plugin.webresource

.SingleDownloadableResourceBuilder] Unable to find resource for plugin: jira-gadget-tutorial-plugin and path: i18n/ALL_ALL.xml

[INFO] [talledLocalContainer] 2014-04-24 15:50:00,490 DirectoryEntryResolverThread-9 WARN admin 949x429x1 rjvzmn 14.99.99.234 /rest/config/1.0/directory.json [gadgets.renderer.internal.GadgetSpecFacto

ryImpl] Error occurred while retrieving gadget spec for rest/gadgets/1.0/g/com.atlassian.plugins.tutorial.jira-gadget-tutorial-plugin:tutorial-gadget/gadget.xml

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 23, 2014

I don't think you've fixed the i8n error - the third INFO line says it can't find the file.

Jayashree Shetty
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.
April 23, 2014

i have attached the image for reference. i have a i18n folder and ALL_ALL.xml file within it.

Jayashree Shetty
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.
April 24, 2014

i did i thought. Because now i have placed the file in the correct path. Here's the snapshot. i could not attach the screenshot in the comment. It didnt give me any error but was unablt to see the image so i attached to the main question above.

Now there's a new warning. But when i try login in to the jira it doesnot allow.

A servlet POST request, to the URI http://aaeinbr132927l:2990/jira/rest/gadget/1.0/login, contains form parameters in the request body but the request body has been consumed by the servlet or a servlet filter accessing the request parameters. Only resource methods using @FormParam will work as expected. Resource methods consuming the request body by other means will not work as expected.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 24, 2014

Hmm. That's implying the code is all in the right place, but I have no idea what that error message means.

As I'm out of my depth on that one, I'd suggest posting it as a new question for more visibility.

Ravi Singh January 17, 2016

Hi, I am using 

Tutorial - Writing a plugin gadget that shows days left in a version

with JIRA SDK 6.2.2 jdk1.8 but I am not able to render the result.Please could you provide me source code for it...thanks in advance

Ravi Singh January 17, 2016

Hi,I am using SDK 6.2.2,JDK 1.8 for 

Tutorial - Writing a plugin gadget that shows days left in a version

but getting errors on DashBoard:

"This gadget cannot be displayed on your dashboard. This could be due to a licensing problem or an application error. If you need this gadget, contact your administrator for assistance. Otherwise, you can remove it from your dashboard."

and some time

"The resource /rest/tutorial-gadget/1.0/days-left-in-iteration/getVersions, cannot be found."

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 17, 2016

Your plugin has said "there's a file called getVersions in here", and then not actually included it in the place it says.  Check the exact definitions for all the files and classes in the add-on.

Ravi Singh January 18, 2016
for error url :"The resource /rest/tutorial-gadget/1.0/days-left-in-iteration/getVersions," 
"getVersions" is path url,below is code-

@Path ("/days-left-in-iteration")
@AnonymousAllowed
@Produces ({ MediaType.APPLICATION_JSON })
public class DaysLeftInVersionResource
{

--------------

--------------

@GET
@Path ("/getVersions")

public Response getVersionsForProject(@QueryParam ("projectId") String projectIdString)
{

--------------

--------------

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 19, 2016

Hmm.  It works for me.  What have you changed in the code?

Ravi Singh January 19, 2016

changes in only pom.xml:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>com.atlassian.plugins.tutorial</groupId>
<artifactId>jira-gadget-tutorial.plugin</artifactId>
<version>1.0-SNAPSHOT</version>

<organization>
<name>Example Company</name>
<url>http://www.example.com/</url>
</organization>

<name>jira-gadget-tutorial.plugin</name>
<description>This is the com.atlassian.plugins.tutorial:jira-gadget-tutorial.plugin plugin for Atlassian JIRA.</description>
<packaging>atlassian-plugin</packaging>

<dependencies>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-api</artifactId>
<version>${jira.version}</version>
<scope>provided</scope>
</dependency>
<!-- Add dependency on jira-core if you want access to JIRA implementation classes as well as the sanctioned API. -->
<!-- This is not normally recommended, but may be required eg when migrating a plugin originally developed against JIRA 4.x -->
<!--
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-core</artifactId>
<version>${jira.version}</version>
<scope>provided</scope>
</dependency>
-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-annotation</artifactId>
<version>${atlassian.spring.scanner.version}</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-runtime</artifactId>
<version>${atlassian.spring.scanner.version}</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<scope>provided</scope>
</dependency>
<!--my changes start -->

<dependency>
<groupId>com.atlassian.plugins.rest</groupId>
<artifactId>atlassian-rest-common</artifactId>
<version>1.0.2</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-plugin</artifactId>
<version>${jira.version}</version>
<scope>provided</scope>
</dependency>

<!--my changes end -->

<!-- WIRED TEST RUNNER DEPENDENCIES -->
<dependency>
<groupId>com.atlassian.plugins</groupId>
<artifactId>atlassian-plugins-osgi-testrunner</artifactId>
<version>${plugin.testrunner.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.2-atlassian-1</version>
</dependency>

<!-- Uncomment to use TestKit in your project. Details at https://bitbucket.org/atlassian/jira-testkit -->
<!-- You can read more about TestKit at https://developer.atlassian.com/display/JIRADEV/Plugin+Tutorial+-+Smarter+integration+testing+with+TestKit -->
<!--
<dependency>
<groupId>com.atlassian.jira.tests</groupId>
<artifactId>jira-testkit-client</artifactId>
<version>${testkit.version}</version>
<scope>test</scope>
</dependency>
-->
</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-jira-plugin</artifactId>
<version>${amps.version}</version>
<extensions>true</extensions>
<configuration>
<productVersion>${jira.version}</productVersion>
<productDataVersion>${jira.version}</productDataVersion>
<!-- Uncomment to install TestKit backdoor in JIRA. -->
<!--
<pluginArtifacts>
<pluginArtifact>
<groupId>com.atlassian.jira.tests</groupId>
<artifactId>jira-testkit-plugin</artifactId>
<version>${testkit.version}</version>
</pluginArtifact>
</pluginArtifacts>
-->
<enableQuickReload>true</enableQuickReload>
<enableFastdev>false</enableFastdev>
<instructions>
<Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>

<!-- Add package to export here -->
<Export-Package>
com.atlassian.plugins.tutorial.api,
</Export-Package>

<!-- Add package import here -->
<Import-Package>
org.springframework.osgi.*;resolution:="optional",
org.eclipse.gemini.blueprint.*;resolution:="optional",
*
</Import-Package>

<!-- Ensure plugin is spring powered - see https://extranet.atlassian.com/x/xBS9hQ -->
<Spring-Context>*</Spring-Context>
</instructions>
</configuration>
</plugin>

<plugin>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-maven-plugin</artifactId>
<version>1.2.6</version>
<executions>
<execution>
<goals>
<goal>atlassian-spring-scanner</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
<configuration>
<scannedDependencies>
<dependency>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-external-jar</artifactId>
</dependency>
</scannedDependencies>
<verbose>false</verbose>
</configuration>
</plugin>
</plugins>
</build>

<properties>
<jira.version>7.0.8</jira.version>
<amps.version>6.2.1</amps.version>
<plugin.testrunner.version>1.2.3</plugin.testrunner.version>
<atlassian.spring.scanner.version>1.2.6</atlassian.spring.scanner.version>
<!-- This key is used to keep the consistency between the key in atlassian-plugin.xml and the key to generate bundle. -->
<atlassian.plugin.key>${project.groupId}.${project.artifactId}</atlassian.plugin.key>
<!-- TestKit version 6.x for JIRA 6.x -->
<testkit.version>6.3.11</testkit.version>
</properties>

</project>

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 19, 2016

 What happens if you use the code as given in the tutorial?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 20, 2016

Ah, hang on, I bet you're trying this for a later version of JIRA.  It works fine for me when I compile it for JIRA 4.  I haven't tried later versions, where you'd need to update the imports and code for new libraries.

Ravi Singh January 20, 2016

Hi,I want to create plugin gadget with SDK 6 and JDK 1.8?...show the code for these versions

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 27, 2016
Ravi Singh March 10, 2016
what is the solution for following error...
 
[INFO] [talledLocalContainer] com.atlassian.util.concurrent.LazyReference$InitializationException: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with na
me 'com.atlassian.plugins.tutorial.DaysLeftInVersionResource': Unsatisfied dependency expressed through constructor argument with index 0 of type [com.atlassian.jira.bc.issue.search.SearchServ
ice]: : No qualifying bean of type [com.atlassian.jira.bc.issue.search.SearchService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.
Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.atlassian.jira.bc.issue.search.SearchService] f
ound for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 13, 2016

Hmm, the sample might be out of date.  Does the tutorial work?

Ravi Singh March 31, 2016

how to render the other fields like due date,updated,created in this same application

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 31, 2016

Add calls to them to the .vm

TAGS
AUG Leaders

Atlassian Community Events