Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include JIRA REST Java Client in a JIRA plugin?

I'm new with JIRA plugin development, so my question might sound too easy, but please be patient and read it carefully, because I've tried so many things, found on the internet, and none of them worked. That's why I'm asking it here, as my last hope.

I would like to use JIRA REST Java Client in my JIRA plugin. The straight forward instructions suggest to add the following into my pom.xml and everything should work:

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

but of course, it doesn't, because in Eclipse, everything shows fine (without any errors/warnings) after atlas-mvn eclipse:eclipse, but when I run JIRA with atlas-run or atlas-debug, as soon as I try to access the line:

JerseyJiraRestClientFactory f = new JerseyJiraRestClientFactory();

I get the exception java.lang.NoClassDefFoundError: com/atlassian/jira/rest/client/internal/jersey/JerseyJiraRestClientFactory

I repeat, in Eclipse, everything shows ok, without a single warning/error mark, but at runtime, I get that exception.

The solution that was recommended to me was to add all the needed dependencies into my pom.xml which I did, but then I wasn't able to even start JIRA normally, due to so many exceptions (will provide them if needed).

So, simple question is how to do this properly? Even better, does anyone have any simple WORKING example of the pom.xml file + src/ folder to provide, so I can figure out where am I mistaking?

Thanks so much in advance.

like image 436
Mladen B. Avatar asked Jul 26 '13 12:07

Mladen B.


2 Answers

As mentioned in the jrjc-example-client repository the current version of JRJC is 2.0 and an important thing has been mentioned in provided pom.xml file:

"JIRA already provides a number of dependencies that JRJC needs. We need to exclude them from the JRJC dependency as we don't want to package them up inside the plugin."

so, the solution is to exclude those things from the JRJC dependency:

<dependency>
        <groupId>com.atlassian.jira</groupId>
        <artifactId>jira-rest-java-client</artifactId>
        <version>2.0.0-m2</version>
        <!--
        JIRA will already provide a number of dependencies that JRJC needs. We need to exclude them from the
        JRJC dependency as we don't want to package them up inside the plugin.
        -->
        <exclusions>
                <exclusion>
                        <groupId>commons-logging</groupId>
                        <artifactId>commons-logging</artifactId>
                </exclusion>
                <exclusion>
                        <groupId>joda-time</groupId>
                        <artifactId>joda-time</artifactId>
                </exclusion>
                <exclusion>
                        <groupId>com.sun.jersey</groupId>
                        <artifactId>jersey-json</artifactId>
                </exclusion>
                <exclusion>
                        <groupId>com.google.guava</groupId>
                        <artifactId>guava</artifactId>
                </exclusion>
                <exclusion>
                        <groupId>com.atlassian.sal</groupId>
                        <artifactId>sal-api</artifactId>
                </exclusion>
                <exclusion>
                        <groupId>com.atlassian.event</groupId>
                        <artifactId>atlassian-event</artifactId>
                </exclusion>
                <exclusion>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-api</artifactId>
                </exclusion>
                <exclusion>
                        <groupId>commons-lang</groupId>
                        <artifactId>commons-lang</artifactId>
                </exclusion>
                <exclusion>
                        <groupId>commons-codec</groupId>
                        <artifactId>commons-codec</artifactId>
                </exclusion>
                <exclusion>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-context</artifactId>
                </exclusion>
                <exclusion>
                        <groupId>com.sun.jersey</groupId>
                        <artifactId>jersey-core</artifactId>
                </exclusion>
        </exclusions>
</dependency>
like image 151
Mladen B. Avatar answered Oct 04 '22 23:10

Mladen B.


This may not be a direct answer to your question, but may give you some leads in the right direction.

JIRA wields a double edged sword, the OSGI container. Things that look fine when developing in your local environment bomb when you deploy. You may have luck tracing down things from the OSGI perspective. Been there, have been burnt few times. HTH.

like image 26
JVXR Avatar answered Oct 04 '22 22:10

JVXR