2

我正在创建一个 Java Web 应用程序。我添加了 Jira API jar 用于连接到 Jira 以获取在 Jira 中创建的问题。

这是我解决问题的 Java 程序

import java.net.URI;
import java.net.URISyntaxException;

import com.atlassian.jira.rest.client.JiraRestClient;
import com.atlassian.jira.rest.client.NullProgressMonitor;
import com.atlassian.jira.rest.client.domain.Issue;
import com.atlassian.jira.rest.client.internal.jersey.JerseyJiraRestClientFactory;

public class AppJIRADataCollector {

    final static JerseyJiraRestClientFactory factory = new JerseyJiraRestClientFactory();
    public static void main(String args[])
    {
        AppJIRADataCollector appJira=new AppJIRADataCollector();
        appJira.getIssues("http://localhost:8080/", "AP-1", "admin", "admin");
    }

    public void getIssues(String issueURI,String issueKey,String username, String password) {

        try {
            final URI jiraServerUri = new URI(issueURI);
            final JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri,username, password);
            System.out.println(restClient);
            final NullProgressMonitor pm = new NullProgressMonitor();
            final Issue issue = restClient.getIssueClient()
                    .getIssue(issueKey, pm);

            System.out.println(issue);
        } catch (URISyntaxException e) {
            System.out.println("URI not found");
            e.printStackTrace();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}

当我运行这个程序时,我在打印问题时得到了正确的输出。

但是当我将它作为 Web 应用程序运行并getIssues()从 servlet 调用该方法时,tomcat 显示NoSuchMethodError

这是堆栈跟踪

java.lang.NoSuchMethodError: com.google.common.collect.Iterables.contains(Ljava/lang/Iterable;Ljava/lang/Object;)Z
    com.atlassian.jira.rest.client.internal.json.IssueJsonParser.parse(IssueJsonParser.java:216)
    com.atlassian.jira.rest.client.internal.json.IssueJsonParser.parse(IssueJsonParser.java:59)
    com.atlassian.jira.rest.client.internal.jersey.AbstractJerseyRestClient$1.call(AbstractJerseyRestClient.java:85)
    com.atlassian.jira.rest.client.internal.jersey.AbstractJerseyRestClient.invoke(AbstractJerseyRestClient.java:54)
    com.atlassian.jira.rest.client.internal.jersey.AbstractJerseyRestClient.getAndParse(AbstractJerseyRestClient.java:80)
    com.atlassian.jira.rest.client.internal.jersey.JerseyIssueRestClient.getIssue(JerseyIssueRestClient.java:131)
    com.atlassian.jira.rest.client.internal.jersey.JerseyIssueRestClient.getIssue(JerseyIssueRestClient.java:123)
    com.domain.jirademo.adapters.AppJIRADataCollector.getIssues(AppJIRADataCollector.java:22)
    com.domain.jirademo.controllers.ProjectDefectsServlet.doPost(ProjectDefectsServlet.java:50)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

为什么会这样?JAR 有什么问题吗?我正在使用 Maven。如果需要我也会发布pom

编辑

我只是后来才添加了 main 方法。所以在堆栈跟踪中,第 22 行是指

final Issue issue = restClient.getIssueClient()
                        .getIssue(issueKey, pm);
4

1 回答 1

2

NoSuchMethodError 它是由版本不匹配引起的,您应该检查您的番石榴库版本。

于 2013-11-24T01:14:21.093 回答