java 未找到类定义输入/分类/赋格/供应商JIRA错误

u0njafvf  于 2023-02-28  发布在  Java
关注(0)|答案(3)|浏览(130)

我尝试使用https://www.baeldung.com/jira-rest-api之后的Java SDK列出JIRA项目(我在Google中找不到其他示例),代码如下:

public static void main(String[] args) {

    JiraRestClient jiraRestClient = getJiraRestClient(URI.create("uri"),"username","token");

    try {
        Iterable<BasicProject> projects =  jiraRestClient.getProjectClient().getAllProjects().get();
        projects.forEach(basicProject -> System.out.println(basicProject.getName()));
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    } catch (ExecutionException e) {
        throw new RuntimeException(e);
    }
}

private static JiraRestClient getJiraRestClient(URI uri, String username, String password) {
    return new AsynchronousJiraRestClientFactory()
            .createWithBasicHttpAuthentication(uri, username, password);
}

但是,它返回以下错误:

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 com.atlassian.jira.rest.client.internal.async.AsynchronousHttpClientFactory.createClient(AsynchronousHttpClientFactory.java:68)
    at com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory.create(AsynchronousJiraRestClientFactory.java:36)
    at com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory.createWithBasicHttpAuthentication(AsynchronousJiraRestClientFactory.java:42)
    at JiraPlayground.getJiraRestClient(JiraPlayground.java:30)
    at JiraPlayground.main(JiraPlayground.java:13)
Caused by: java.lang.ClassNotFoundException: io.atlassian.fugue.Suppliers
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 8 more

以下是我的依赖项:

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

        <!-- https://mvnrepository.com/artifact/io.atlassian.fugue/fugue -->
        <dependency>
            <groupId>io.atlassian.fugue</groupId>
            <artifactId>fugue</artifactId>
            <version>5.0.0</version>
            <scope>provided</scope>
        </dependency>

知道如何正确运行代码吗?

4nkexdtk

4nkexdtk1#

这是一个很长的机会,但我建议将库 fugue 的范围从provided更改为compile,然后重试...

vcirk6k6

vcirk6k62#

这对我很有效:

<?xml version="1.0" encoding="UTF-8"?>
<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>org.example</groupId>
    <artifactId>untitled1</artifactId>
    <version>1.0-SNAPSHOT</version>

    <repositories>
        <repository>
            <id>Atlassian</id>
            <url>https://packages.atlassian.com/mvn/maven-atlassian-external/</url>
        </repository>
    </repositories>

    <properties>
        <maven.compiler.source>16</maven.compiler.source>
        <maven.compiler.target>16</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-rest-java-client-core</artifactId>
            <version>5.2.4</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>5.0.0</version>
        </dependency>
    </dependencies>

</project>

https://stackoverflow.com/a/75527051/309683中所述,如果您在Jira外部运行应用程序(例如,不是插件/扩展),请确保fuge未标记为provided
那么下面的代码应该可以工作:

package org.example;

import com.atlassian.jira.rest.client.api.JiraRestClient;
import com.atlassian.jira.rest.client.api.JiraRestClientFactory;
import com.atlassian.jira.rest.client.api.domain.BasicProject;
import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory;

import java.net.URI;

public class Main {
    private static final String JIRA_URL = "https://your-jira-url.com";
    private static final String JIRA_USERNAME = "your-jira-username";
    private static final String JIRA_PASSWORD = "your-jira-password";

    public static void main(String[] args) throws Exception {
        URI jiraServerUri = new URI(JIRA_URL);
        JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
        try (JiraRestClient client = factory.createWithBasicHttpAuthentication(jiraServerUri, JIRA_USERNAME, JIRA_PASSWORD)) {
            Iterable<BasicProject> projects = client.getProjectClient().getAllProjects().claim();
            for (BasicProject project : projects) {
                System.out.println(project.getKey() + ": " + project.getName());
            }
        }
    }
}
brgchamk

brgchamk3#

io.atlassian.fugue.Suppliers类是JRJC maven依赖项中未包含的不同工件的一部分。这会在运行时导致异常。
尝试将以下依赖项添加到pom.xml

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

<dependency>
<groupId>io.atlassian.fugue</groupId>
<artifactId>fugue</artifactId>
<version>4.7.2</version>
<scope>provided</scope>
</dependency>

相关问题