Missed Team ’24? Catch up on announcements here.

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

Can anyone provide a simple example of JIRA REST Java Client (JRJC) plugin code?

MB
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.
July 24, 2013

Does anyone have a simple example (git repository or a zip file) of the most basic JIRA plugin using JRJC?

I'm asking this because I've read so many pages on the internet, in the last couple of days, trying to resolve a problem with JRJC runtime dependencies and even asked a couple of questions here, on Answers, without success. In Eclipse, the code looks just fine, no errors/warnings reported, but when I start atlas-run or atlas-debug, it throws ClassNotFound runtime exception(s), when trying to access Rest Client Factory.

I'll provide my test plugin's code for anyone who wants to check what could be wrong with it. I was really only following tutorials here and here. The plugin is a simple listener created from an official tutorial, with just one thing added - calling a method that should do a simple rest request. So, if you manage to start JIRA (using atlassian sdk), just create a new issue and try to catch the first line of the test2() method in your debugger, just to see what happens.

The source code is here: http://www1.datafilehost.com/d/a3b519ba

The log of the atlas-debug is here: http://www1.datafilehost.com/d/80b0f38a

Thank you in advance.

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 31, 2013

Here's an example of using the JRJC (version 2.0.0-m2) within a JIRA plugin. I tested it against JIRA 6.0 - https://bitbucket.org/jaysee00/jrjc-example-client/src/e01e0da6d72e06aa21b0a8fe5c23d62b97192ca9/plugin?at=master

MB
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.
July 31, 2013

Hi Joseph and thank you a lot for making an effort to provide an example of the working jrjc code!

However, I tried to do "git clone" and then "atlas-run" / "atlas-debug" to test it out of the box, but the same "NoClassDefFoundError" appears, as usual:

[INFO] [talledLocalContainer] 2013-08-01 08:48:29,605 http-bio-2990-exec-1 ERROR admin 528x1324x1 o4rbdp 127.0.0.1 /plugins/servlet/jrjc [atlassian.plugin.module.PrefixDelegatingModuleFactory] Detected an error (NoClassDefFoundError) instantiating the module for plugin 'com.atlassian.jira.examples.jrjc-example-plugin' for module 'example-servlet': com/atlassian/jira/rest/client/JiraRestClientFactory.  This error is usually caused by your plugin using a imported component class that itself relies on other packages in the product. You can probably fix this by adding the missing class's package to your <Import-Package> instructions; for more details on how to fix this, see https://developer.atlassian.com/display/DOCS/NoClassDefFoundError .
[INFO] [talledLocalContainer] 2013-08-01 08:48:29,606 http-bio-2990-exec-1 ERROR admin 528x1324x1 o4rbdp 127.0.0.1 /plugins/servlet/jrjc [atlassian.plugin.servlet.DefaultServletModuleManager] Unable to create servlet
[INFO] [talledLocalContainer] com.atlassian.util.concurrent.LazyReference$InitializationException: java.lang.NoClassDefFoundError: com/atlassian/jira/rest/client/JiraRestClientFactory
[INFO] [talledLocalContainer] 	at com.atlassian.util.concurrent.LazyReference.getInterruptibly(LazyReference.java:149)
[INFO] [talledLocalContainer] 	at com.atlassian.util.concurrent.LazyReference.get(LazyReference.java:112)

Here is the complete log: http://pastebin.com/UXqPvyZp

Do you have any idea what is wrong?

MB
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.
July 31, 2013

I don't know what to say, but at one point, things started working properly... So I decided to create a new clean directory and again do "git clone" and "atlas-run" and now everything works out of the box. I can only imagine something got updated in the process or something, so now things are working properly.

I can't describe how much you helped me with this answer! Thank you so much!

Feel free to send me your postal address (in private message) and I'll arrange the biggest beer keg available in your area to be delivered to your location! :)

Thank you again so much! :)

Remigiusz Jackowski
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.
July 31, 2013

This example looks much better than any atlassian tutorial / code generated by SDK I've seen. Thanks :)

Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 31, 2013

Glad to help!

The problem with things "suddenly" working properly may have been because you had a dirty target/ directory in your project, with some old dependencies still being bundled up in your plugin.

Running "atlas-clean" is always a good troubleshooting step :-)

MB
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.
August 1, 2013

Could be, but I highly doubt it, because in both cases I've created a new subdir, did "git clone" and then "atlas-run"... I don't know why it didn't work the first time I tried it but now it works great :) Thank you a lot again! :)

Joe July 17, 2014

Hello,

Thanks for the example. I had been looking at the incorrect place for quite some time.

I downloaded and built jira-rest-java-client 2.0.0-m30 and Im using your code. Im getting the following error:

**********************************************************************************************

* JIRA Java REST Client ('JRJC') example. *

* NOTE: Start JIRA using the Atlassian Plugin SDK before running this example. *

* (for example, use 'atlas-run-standalone --product jira --version 6.0 --data-version 6.0'.) *

**********************************************************************************************

Logging in to https://xxx.atlassian.netwith username 'xxx' and password 'xxx'

Exception in thread "main" java.lang.NoClassDefFoundError: com/atlassian/sal/api/ApplicationProperties

at com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory.create(AsynchronousJiraRestClientFactory.java:35)

at com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory.createWithBasicHttpAuthentication(AsynchronousJiraRestClientFactory.java:42)

at HelloWorld.main(HelloWorld.java:38)

Caused by: java.lang.ClassNotFoundException: com.atlassian.sal.api.ApplicationProperties

at java.net.URLClassLoader$1.run(URLClassLoader.java:366)

at java.net.URLClassLoader$1.run(URLClassLoader.java:355)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:354)

at java.lang.ClassLoader.loadClass(ClassLoader.java:425)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)

at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

... 3 more

Any thoughts on what Im missing.

Thanks

Joe

Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 18, 2014

Hi Joe,

I am unable to locate jira-rest-java-client 2.0.0-m30 - the latest versions that I can see is 2.0.0-m2.

Where did you get it from?

praveen joshi April 25, 2016

Hi Joe,

I tried your example snippet but I am facing exception:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/nio/NHttpMessageParserFactory
at org.apache.http.impl.nio.conn.PoolingClientAsyncConnectionManager.createClientAsyncConnectionFactory(PoolingClientAsyncConnectionManager.java:96)
at org.apache.http.impl.nio.conn.PoolingClientAsyncConnectionManager.<init>(PoolingClientAsyncConnectionManager.java:72)
at com.atlassian.httpclient.apache.httpcomponents.DefaultHttpClient$2.<init>(DefaultHttpClient.java:117)
at com.atlassian.httpclient.apache.httpcomponents.DefaultHttpClient.<init>(DefaultHttpClient.java:115)
at com.atlassian.jira.rest.client.internal.async.AsynchronousHttpClientFactory.createClient(AsynchronousHttpClientFactory.java:53)
at com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory.create(AsynchronousJiraRestClientFactory.java:35)
at com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory.createWithBasicHttpAuthentication(AsynchronousJiraRestClientFactory.java:41)
at com.praveen.jira.JiraPoc.main(JiraPoc.java:65)

 

 

Please help as I am using this as my College project submission.

0 votes
Nitram
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.
July 25, 2013

Hi,

Look at these links, you will get an idea of how to do it or it may help you in some way.

https://answers.atlassian.com/questions/149940/create-issue-with-jira-rest-java-client

Hope this Helps.

0 votes
MB
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.
July 25, 2013

If I remove "<scope>compile</scope>" from this:

&lt;dependency&gt;
	&lt;groupId&gt;com.atlassian.jira&lt;/groupId&gt;
	&lt;artifactId&gt;jira-rest-java-client&lt;/artifactId&gt;
	&lt;version&gt;1.1-m02&lt;/version&gt;
	&lt;scope&gt;compile&lt;/scope&gt;
&lt;/dependency&gt;

then I get "JIRA startup failed, JIRA has been locked." and here is the log of atlas-debug: http://www.datafilehost.com/d/4320be51

TAGS
AUG Leaders

Atlassian Community Events