You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Basic认证创建JiraRestClient时遇NoClassDefFoundError问题排查

解决Jira REST Client初始化时的NoClassDefFoundError问题

问题场景

尝试通过Basic认证创建JiraRestClient,代码实现如下:

JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
URI jiraServerUri = new URI("*");
try (JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri, username, password)) {
    App.restClient = restClient;
    final Issue issue = getIssue("DEV-1");
    System.out.println(issue.getDescription());
}

运行时抛出如下异常:

Exception in thread "main" java.lang.NoClassDefFoundError: io/atlassian/fugue/Suppliers
at com.atlassian.httpclient.apache.httpcomponents.ApacheAsyncHttpClient.<clinit>(ApacheAsyncHttpClient.java:80)
at com.atlassian.httpclient.apache.httpcomponents.DefaultHttpClientFactory.doCreate(DefaultHttpClientFactory.java:61)
at com.atlassian.httpclient.apache.httpcomponents.DefaultHttpClientFactory.create(DefaultHttpClientFactory.java:36)
at ...
     Process finished with exit code 1

当前使用的Maven依赖片段:

<dependencies>
    <dependency>
      <groupId>com.atlassian.jira</groupId>
      <artifactId>jira-rest-java-client-core</artifactId>
      <version>5.2.0</version>
    </dependency>
    <dependency>
      <groupId>com.atlassian.jira</groupId>
      <artifactId>jira-rest-java-client-api</artifactId>
      <version>5.2.4</version>
    </dependency>
    <dependency>
      <groupId>io.atlassian.fugue</groupId>
      <artifactId>fugue</artifactId>
      <version>4.7.2</version>
      <type>pom</type>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
    </dependency>
      <dependency>
      <groupId>commons-codec</groupId>
      <artifactId>commons-codec</artifactId>
      <version>1.13</version>
    </dependency>
    <dependency>
      <groupId>commons-httpclient</groupId>
      <artifactId>commons-httpclient</artifactId>
      <version>3.1</version>
    </dependency>
    <dependency>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
      <version>1.0.4</version>
    </dependency>
    <dependency>
      <groupId>org.example</groupId>
      <artifactId>JiraIntegratorLibrary</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
  </dependencies>

问题分析

  1. fugue依赖配置错误:保留<type>pom</type>会让Maven只下载pom文件,不会引入包含io.atlassian.fugue.Suppliers类的jar包,直接触发NoClassDefFoundError。
  2. Jira Client版本不一致:jira-rest-java-client-core(5.2.0)和jira-rest-java-client-api(5.2.4)版本不匹配,可能引发依赖冲突或类加载异常。
  3. 冗余依赖:commons-httpclient等属于Jira REST Client的传递依赖,手动引入可能导致版本冲突。

修复方案

修正后的Maven依赖

<dependencies>
    <!-- 统一Jira REST Client的API和Core版本 -->
    <dependency>
        <groupId>com.atlassian.jira</groupId>
        <artifactId>jira-rest-java-client-api</artifactId>
        <version>5.2.4</version>
    </dependency>
    <dependency>
        <groupId>com.atlassian.jira</groupId>
        <artifactId>jira-rest-java-client-core</artifactId>
        <version>5.2.4</version>
    </dependency>
    <!-- 修正fugue依赖,移除pom类型,确保引入jar包 -->
    <dependency>
        <groupId>io.atlassian.fugue</groupId>
        <artifactId>fugue</artifactId>
        <version>4.7.2</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope> <!-- 测试依赖添加test范围,减少生产环境冗余 -->
    </dependency>
    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>1.13</version>
    </dependency>
    <dependency>
        <groupId>org.example</groupId>
        <artifactId>JiraIntegratorLibrary</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
</dependencies>

额外说明

  • 移除commons-httpclient和commons-logging,Jira REST Client会通过传递依赖引入正确版本的库,避免版本冲突。
  • 给JUnit依赖添加<scope>test</scope>,仅在测试阶段生效,减少生产环境依赖体积。

内容的提问来源于stack exchange,提问作者KaanEm

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 07:12:42