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

JIRA REST client proper usage

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 21, 2013

How to properly add a JIRA REST client into an already existing JIRA plugin?

I've tried following this tutorial: https://ecosystem.atlassian.net/wiki/display/JRJC/Tutorial

and I've added the following dependency to my pom.xml:

<dependency>
	<groupId>com.atlassian.jira</groupId>
	<artifactId>jira-rest-java-client</artifactId>
	<version>1.1-m02</version>
	<scope>provided</scope>
</dependency>

now, in eclipse (after atlas-mvn eclipse:eclipse) everything shows fine, without any warnings/errors, but at runtime, this line:

JerseyJiraRestClientFactory f = new JerseyJiraRestClientFactory();

gives me an exception like:

java.lang.NoClassDefFoundError "com/atlassian/jira/rest/client/internal/jersey/JerseyJiraRestClientFactory"

Does anyone know how to add/use jira-rest-java-client properly to an already existing plugin?

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
Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 31, 2013
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

Excellent answer!

Thanks a lot for providing it! :)

1 vote
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.
July 21, 2013

Put the scope as compile. JRJC is not part of JIRA and so you will need those classes in the plugins classpath.

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 21, 2013

You're the man Jobin!!! :)))

It worked like a charm :) But.. :)

Now, I'm getting the exception "java.lang.NoClassDefFoundError: Could not initialize class org.apache.commons.httpclient.HttpState" at line:

jc = f.createWithBasicHttpAuthentication(new URI("http://localhost:8080"), "admin", "admin");

the test code I tried to execute was something simple:

private void blah() {
	JerseyJiraRestClientFactory f = new JerseyJiraRestClientFactory();
	JiraRestClient jc;
	try {
		jc = f.createWithBasicHttpAuthentication(new URI("http://localhost:8080"), "admin", "admin");

		SearchResult r = jc.getSearchClient().searchJql("type = Bug ORDER BY RANK ASC", null);

		for (BasicIssue basicIssue : r.getIssues()) {
			com.atlassian.jira.rest.client.domain.Issue issue = jc.getIssueClient().getIssue(basicIssue.getKey(), null);
			System.out.println("Bug: " + issue.getKey() + " " + issue.getSummary());
			for (IssueLink issueLink : issue.getIssueLinks()) {
				com.atlassian.jira.rest.client.domain.Issue issueL = jc.getIssueClient().getIssue((issueLink).getTargetIssueKey(), null);
				System.out.println(issueLink.getIssueLinkType().getDescription() + ": " + issueL.getKey() + " " + issueL.getSummary() + " " + issueL.getFieldByName("Story Points").getValue());
			}
		}
	} catch (URISyntaxException e) {
		// TODO
	}
}

I'll accept your answer, because it solved my initial question though :)

Thanks once again! :)

P.S. Does anyone know how to notify author of that doc page to update the page with <scope>compile</scope>

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

It is the same thing. You are missing another class at runtime. I guess apache httpclient this time. I wonder why it is not pulled in by JRJC dependency but see if you can fix it by adding it in your pom.xml.

https://ecosystem.atlassian.net/wiki/display/JRJC/Project+Dependencies shows the dependencies for JRJC. They should normally be pulled in by JRJC.

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 21, 2013

I was afraid you were going to say that :)

Anyway, thanks a lot again!

0 votes
sudheer test February 17, 2014

Use jira-rest-java-client-api instead of jira-rest-java-client.

I too faced the same issue.

https://answers.atlassian.com/questions/258302/how-disconnect-after-making-connection-createwithbasichttpauthentication

0 votes
Timothy
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 21, 2013

Just a curious question. Why do you need the REST client when the add on already provides you access to most of the API?

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 21, 2013

I'm not sure I quite understand your question, but I need to implement a plugin, which will serve as a kind of a proxy for the gadget's REST calls (retrieving information from another JIRA instance), so at one point my plugin needs to act as a REST service provider (towards the gadget) and at another point (towards another JIRA instance) it needs to act as a REST client, right?

Timothy
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 21, 2013

Yea. That is one way to do it. But you can always just use a Jersey client to call the other REST instead of using the whole JIRA REST client.

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