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

Next challenges

Recent achievements

Recognition

  • Give kudos
  • My kudos

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Jira Java REST Client

Hi,

Please tell me that I am not the only one who has had problems getting the JRJC working? I have tried so many different tutorials/examples and for the life of me cannot get any to work! :sad:  I keep getting dependency errors even when I have the jar in pom.xml or else I'm getting errors because the REST client is not the right type of REST client.

 

At the moment I am getting a "NoClassDefFoundError" for "org/apache/http/conn/HttpRoutePlanner" and from looking it up this seems to come from httpclient jar which I have downloaded and in my pom.xml.

 

I need it for updating issues but at this stage if I got a small simple working example of it doing anything I'd be happy! Does anyone have a small simple working example that I could try? Desperate at this stage!

 

Thanks,

Eimear

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

My advice is give up and use a straight HTTP client. JRJC doesn't support the full REST API and isn't actively supported. I like Unirest: http://unirest.io/java.html

Thanks, will take a look at this. Was hoping to get the JRJC working but have been trying it for so long now am on the verge of giving up - will keep this open for a while in case someone managed to get a simple example working!

I have had it working, it just isn't worth the trouble!

I am new to all of this, and tried the JRJC client, and YES you are not the only one having trouble making it work.

I almost made my decision not to use it, but it still a goog point to start interfacing JIRA through its REST API.

So, i tried and i succeeded to get it work with a simple code : 

package com.atlassian.jira.examples;
import java.net.URI;
import com.atlassian.jira.rest.client.api.JiraRestClient;
import com.atlassian.jira.rest.client.api.JiraRestClientFactory;
import com.atlassian.jira.rest.client.api.domain.Issue;
import com.atlassian.jira.rest.client.api.domain.User;
import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory;
import com.atlassian.util.concurrent.Promise;

/**
 * Entry-point invoked when the jar is executed.
 */
public class Main
{
    private static final String JIRA_URL = "http://localhost:8082";
    private static final String JIRA_ADMIN_USERNAME = "toto";
    private static final String JIRA_ADMIN_PASSWORD = "toto";
    
    public static void main(String[] args) throws Exception
    {
        // Construct the JRJC client
        System.out.println(String.format("Logging in to %s with username '%s' and password '%s'", JIRA_URL, JIRA_ADMIN_USERNAME, JIRA_ADMIN_PASSWORD));
        JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
        URI uri = new URI(JIRA_URL);
        JiraRestClient client = factory.createWithBasicHttpAuthentication(uri, JIRA_ADMIN_USERNAME, JIRA_ADMIN_PASSWORD);
        // Invoke the JRJC Client
        Promise<User> promise = client.getUserClient().getUser("toto");
        User user = promise.claim();
        
        Promise<Issue> promiseIssue = client.getIssueClient().getIssue("TEST-1");
        Issue issue = promiseIssue.claim();
        
        // Print the result
        System.out.println(String.format("Your admin user's email address is: %s\r\n", user.getEmailAddress()));
        
        // Print the result
        System.out.println("some TEST-1 details " + issue.getAssignee() + "   " + issue.getSummary() + "  " + issue.getWorklogs());
        // Done
        System.out.println("Example complete. Now exiting.");
        System.exit(0);
    }
}

With this pom.xml (make sure that you have the com.atlassian.fugue dependency, i am using version 2.6.1)

<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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.atlassian.jira.examples</groupId>
	<artifactId>jrc-example-client-fixed</artifactId>
	<version>1.0-SNAPSHOT</version>
	<packaging>jar</packaging>
	<name>JIRA REST Java Client Example</name>
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>
	<dependencies>
		<dependency>
			<groupId>com.atlassian.fugue</groupId>
			<artifactId>fugue</artifactId>
			<version>2.6.1</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-simple</artifactId>
			<version>1.6.4</version>
		</dependency>
		<dependency>
			<groupId>com.atlassian.jira</groupId>
			<artifactId>jira-rest-java-client-api</artifactId>
			<version>4.0.0</version>
			<exclusions>
				<exclusion>
					<groupId>stax</groupId>
					<artifactId>stax-api</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<!-- JRJC is distributed under the Apache 2.0 license. -->
			<groupId>com.atlassian.jira</groupId>
			<artifactId>jira-rest-java-client-core</artifactId>
			<version>4.0.0</version>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>2.5</version>
				<configuration>
					<source>1.7</source>
					<target>1.7</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

and the most important of all, that you have this repository declared in your maven settings.xml 

<repository>
           <id>atlassian-public</id>
           <url>https://maven.atlassian.com/content/repositories/atlassian-public/</url>
           <snapshots>
             <enabled>false</enabled>
             <updatePolicy>never</updatePolicy>
             <checksumPolicy>warn</checksumPolicy>
           </snapshots>
           <releases>
             <enabled>true</enabled>
             <checksumPolicy>warn</checksumPolicy>
           </releases>
         </repository>

 

 

TAGS
Community showcase
Published in Confluence Cloud

Share your Confluence Cloud experience for a chance to win $500!

Take our 5-minute survey to win a $500 Visa gift card! Are you currently using Confluence Cloud? We want to hear from you! Fill out this quick survey about your Confluence Cloud experience so we ...

136 views 1 8
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you