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

Accessing JIRA using Java

Hello.

I'm just making my first steps with JIRA, so please excuse my questions.

I want to access JIRA using Java and Eclipse.
Here: Remote API Reference it says, the recommended API is REST.
Here: JIRA REST APIs it says, I need the Atlassian REST plugin, but there isn't a download link. Is this the right file: https://maven.atlassian.com/content/repositories/atlassian-public/com/atlassian/jira/jira-rest-java-client/2.0.0-m2/jira-rest-java-client-2.0.0-m2.jar? (I prefer jar files rather than maven dependencies.)

I also found REST Java Client for JIRA, but I'm not sure if it's necessary. It also says, it available for JIRA 5.0 - 6.0, but the latest version ist 6.2.3.

Do I need any more plugins, for example JAX-RS or Jersey?

The number of possibilities confuses me. I just need a list of the plugins and jar files to be able to interact with JIRA.

Thank you!

3 answers

1 accepted

1 vote
Answer accepted

In order to retain sanity, when with JIRA, you really do need to get your head into Maven, as this solves the 'what jars do I need' question. Then you can start a simple Maven project and add in the required dependencies, such as JRJC, and everything else pretty much hangs off that. Get an example maven project working, and build on that.

JRJC will save you some wondering about JSON, the source is available to know more.

Use this in your Maven client project:

<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-core</artifactId>
<version>2.0.0-m30</version>
<scope>provided</scope>
</dependency>

Repo url: https://maven.atlassian.com/content/repositories/atlassian-public/com/atlassian/jira/jira-rest-java-client/2.0.0-m2/

JRJC examples:

- https://ecosystem.atlassian.net/wiki/display/JRJC/Migrating+from+JRJC+1.x+to+2.x

OK, I set up Maven and added this dependency. Then I clicked "Maven->Update project". But I get the following error:

Missing artifact com.atlassian.jira:jira-rest-java-client-core:jar:2.0.0-m30

Like 1 person likes this

For anyone following this from the start, I shoudl have linked the SDK page as well, this bundles a version of Maven configured with the Atlassian repositories, which will be required to resolve artifacts in the com.atlassian domain. You use it from the command line with 'atlas-mvn', eclipse can be configured to use the SDK maven repository. This isn't as great an experience as it could be as the SDK will update itself from time to time, and ide links break due to folder changes.

1 vote

Ah, now there's a number of different things here. Let's start by breaking out the systems and running over what they do and how they could interact (I'm going to over simplify here and probably tell you stuff you already know, but I need to cover it all just in case)

Eclipse is a development environment. There are two basic reasons for mentioning Eclipse alongside Jira

  1. You are going to use Eclipse to develop something FOR Jira
  2. You are writing something using Eclipse, and Jira is the issue tracker that you're keeping your bugs/issues/tasks in.

Note that you could be doing both!

Case 2 is the simple one. Jira is your issue tracker, it's useful to have issue information available in Eclipse, so you connect them using an Eclipse plugin. That's it really. Jira information appears in Eclipse, and you can update Jira information from Eclipse.

Case 1 is the more fuzzy one because when I say "for Jira", I could mean

  1. something that plugs into Jira (I'd advise reading the Jira plugin guides)
  2. A connect plugin that lives alongside Jira (I'd advise a look at the Jira Connect plugin guides)
  3. The core of Jira itself (I'd stay away from that, try to meet your goals without hacking the core, it's a last resort, and only to be done when you've got the basics by trying to write a plugin!)
  4. Something that just talks to Jira from the outside. This is where the REST stuff comes into play (below)
  5. A gadget (which is a mix of 1 and 4!).

Now, REST is an interface Jira exposes to the world so other computers can talk to it. You don't need any plugins to use it - it is a plugin, but it's distributed by default, so if you've installed Jira (4+), you've got it.

You can use the most basic simple REST calls to do stuff in Jira. I've not used REST a lot, but where I have, a lot of it is pretty simple stuff - I'm doing things like using curl in a script to hit one REST url. If I need something more clever, I tend to look at the JRJC for help and guidance, but you don't have to use it. Same for other libraries - if they're useful, use them, but you don't actually need anything to use REST off-the-shelf.

JIRA developers, please consider 

  • providing a single shaded zero-dependency jar instead of sending your potential customers into jar hell to workout the class path conflicts

  • using retrofit instead of bloated apache client: 
<dependency>
  <groupId>com.squareup.retrofit2</groupId>
  <artifactId>retrofit</artifactId>
  <version>2.1.0</version>
</dependency>
  • adding Atlassian prefix to ALL the Atlassian jars

  • improving your logging so it logs the URL it's using

  • get rid of  MavenUtils.getVersion 

  • return the hour of my life wasted on these problems

 

 

Here is an example of the pain you are causing ...

 

 

DETAILS

I just added these two dependencies to my pom:

<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-api</artifactId>
<version>4.0.0</version>
</dependency>


<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-core</artifactId>
<version>4.0.0</version>
</dependency>

 

the build then pulled in 23! jars to my runtime! classpath

 

com/atlassian/event/atlassian-event/2.3.5/atlassian-event-2.3.5.jar (48 KB)
com/atlassian/httpclient/atlassian-httpclient-api/0.23.0/atlassian-httpclient-api-0.23.0.jar (50 KB)
com/atlassian/httpclient/atlassian-httpclient-plugin/0.23.0/atlassian-httpclient-plugin-0.23.0.jar (2123 KB)
com/atlassian/jira/jira-rest-java-client-api/4.0.0/jira-rest-java-client-api-4.0.0.jar (149 KB)
com/atlassian/jira/jira-rest-java-client-core/4.0.0/jira-rest-java-client-core-4.0.0.jar (187 KB)
com/atlassian/sal/sal-api/3.0.3/sal-api-3.0.3.jar (72 KB)
com/atlassian/util/concurrent/atlassian-util-concurrent/2.4.2/atlassian-util-concurrent-2.4.2.jar (133 KB)


com/sun/jersey/jersey-client/1.5/jersey-client-1.5.jar (126 KB)
com/sun/jersey/jersey-core/1.5/jersey-core-1.5.jar (445 KB)
com/sun/jersey/jersey-json/1.5/jersey-json-1.5.jar (142 KB)
com/sun/xml/bind/jaxb-impl/2.2.3/jaxb-impl-2.2.3.jar (870 KB)

javax/xml/bind/jaxb-api/2.2.2/jaxb-api-2.2.2.jar (103 KB)

org/apache/httpcomponents/httpasyncclient-cache/4.1/httpasyncclient-cache-4.1.jar (35 KB)
org/apache/httpcomponents/httpasyncclient/4.1.2/httpasyncclient-4.1.2.jar (173 KB)
org/apache/httpcomponents/httpclient-cache/4.4.1/httpclient-cache-4.4.1.jar (156 KB)
org/apache/httpcomponents/httpcore-nio/4.4.5/httpcore-nio-4.4.5.jar (348 KB)
org/apache/httpcomponents/httpmime/4.5.2/httpmime-4.5.2.jar (41 KB)

org/codehaus/jackson/jackson-core-asl/1.5.5/jackson-core-asl-1.5.5.jar (168 KB)
org/codehaus/jackson/jackson-jaxrs/1.5.5/jackson-jaxrs-1.5.5.jar (17 KB)
org/codehaus/jackson/jackson-mapper-asl/1.5.5/jackson-mapper-asl-1.5.5.jar (475 KB)
org/codehaus/jackson/jackson-xc/1.5.5/jackson-xc-1.5.5.jar (25 KB)
org/codehaus/jettison/jettison/1.1/jettison-1.1.jar (67 KB)

stax/stax-api/1.0.1/stax-api-1.0.1.jar (26 KB)

 

That produced ClassNotFoundException: com.atlassian.fugue due to a missing jar

 

So I googled, guessed, and added

<dependency>
<groupId>com.atlassian.fugue</groupId>
<artifactId>fugue</artifactId>
<version>2.2.1</version>
</dependency>

 

Then got Null Pointer exception  AsynchronousHttpClientFactory$MavenUtils - Could not find version for maven artifact com.atlassian.jira:jira-rest-java-com.atlassian.jira.rest.client   while calling com.atlassian.jira.rest.client.internal.async.AsynchronousHttpClientFactory$MavenUtils.getVersion

googled, found out spring is overriding your older dependencies ... yep welcome to jar hell.

Searched my WEB-INF/lib folder, noticed I've got two stax-api jars!

mvn dependency:tree

reveals ... both from jira.

+- com.atlassian.jira:jira-rest-java-client-core:jar:4.0.0:compile
| +- com.sun.jersey:jersey-client:jar:1.5:compile
| | \- com.sun.jersey:jersey-core:jar:1.5:compile
| +- com.sun.jersey:jersey-json:jar:1.5:compile
| | +- org.codehaus.jettison:jettison:jar:1.1:compile
| | | \- stax:stax-api:jar:1.0.1:compile
| | +- com.sun.xml.bind:jaxb-impl:jar:2.2.3:compile
| | | \- javax.xml.bind:jaxb-api:jar:2.2.2:compile
| | | \- javax.xml.stream:stax-api:jar:1.0-2:compile

So, I download your latest source from here
mvn install
mvn dependency:tree
found you require 4.4.1 of the httpclient, and my project is using 4.5.2

] +- com.atlassian.httpclient:atlassian-httpclient-plugin:jar:0.23.0:compile
] | +- org.apache.httpcomponents:httpasyncclient-cache:jar:4.1:compile
] | +- org.apache.httpcomponents:httpclient-cache:jar:4.4.1:compile
] | | \- org.apache.httpcomponents:httpclient:jar:4.4.1:compile

Added this exclusion pulling in the 4.5.2 version

<exclusion>
<artifactId>httpclient</artifactId>
<groupId>org.apache.httpcomponents</groupId>
</exclusion>

No love. 

googled, saw this post

http://stackoverflow.com/questions/33135250/can-not-create-asynchronoushttpclientfactory

 

Added this exclusion

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
<exclusions>
<exclusion>
<artifactId>logback-core</artifactId>
<groupId>ch.qos.logback</groupId>
</exclusion>
<exclusion>
<artifactId>logback-classic</artifactId>
<groupId>ch.qos.logback</groupId>
</exclusion>
</exclusions>
</dependency>

 

Money!
got past the exception.. but now my logging is broken, my httpclient is older...and a new error:

 

RestClientException{statusCode=Optional.of(404), errorCollections=[ErrorCollection{status=404, errors={}, errorMessages=[]}]}

 

Stepping through your code I noticed the http client was sending 
/rest/api/latest/rest/api/latest

removed it from my URI, and MONEY!

I reverted back to logback and logging still works, so that was a flase flag.

I still have the propery exception from MavenUtils.getVersion which is obviously not necessary.

 

anyway... you get the drift.  Your java product needs some love.

This was way more trouble it could have been if you had simplified it.

 

<sigh>

  • two year old question ("retiring" outdated stuff came up in a discussion I was in with the Atlassian community leaders about better documentation and Q&A only a few days ago at summit)
  • that's not what jrjc is for
  • Quoting stackoverflow.  Brilliant system.  Some utterly dreadful answers and advice.  You say "return the hour of my life" - there are people wanting weeks back after reading SO postings about Atlassian stuff.  (Ok, might just be me, my cousin and three of my colleagues, but I doubt the damage is that limited)

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published Thursday in Confluence

Confluence CVEs and common questions

Two vulnerabilities have been published for Confluence Server and Data Center recently: March 20, 2019 CVE-2019-3395 / CVE-2019-3396 April 17, 2019 CVE-2019-3398 The goal of this article is...

82 views 0 9
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you