JIRA使用Java创建问题 [英] JIRA creating issue using java

查看:231
本文介绍了JIRA使用Java创建问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是在Java上的JIRA上创建一个新的问题.实际上,我正在实习,之前没有使用过API.这是我在研究JIRA文档时发现的代码.不确定参数是否错误.

What I'm trying to do is creating a new issue on JIRA over Java. Actually I'm on internship and didn't work with APIs before. Here is the code I found while studying JIRA's documents. Not sure if paramaters are wrong.

public class ExampleCreateIssuesAsynchronous {

    private static URI jiraServerUri = URI.create("https://stajtest.atlassian.net/");

    public static void main(String[] args) throws IOException {
        final AsynchronousJiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
        final JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri, "internship2016****", "***************");

        try {
            final List<Promise<BasicIssue>> promises = Lists.newArrayList();
            final IssueRestClient issueClient = restClient.getIssueClient();

            System.out.println("Sending issue creation requests...");
            for (int i = 0; i < 100; i++) {
                final String summary = "NewIssue#" + i;
                final IssueInput newIssue = new IssueInputBuilder("TST", 1L, summary).build();
                System.out.println("\tCreating: " + summary);
                promises.add(issueClient.createIssue(newIssue));
            }
            System.out.println("Collecting responses...");
            final Iterable<BasicIssue> createdIssues = transform(promises, new Function<Promise<BasicIssue>, BasicIssue>() {
                @Override
                public BasicIssue apply(Promise<BasicIssue> promise) {
                    return promise.claim();
                }
            });
            System.out.println("Created issues:\n" + Joiner.on("\n").join(createdIssues));
        } finally {
            restClient.close();
        }
    }
}

我已经学习了2天,而我得到的只是那个错误.任何帮助将不胜感激.

I've studied for 2 days and all I got is that error. Any help would be appreciated.

Exception in thread "main" java.lang.NoClassDefFoundError: com/atlassian/sal/api/executor/ThreadLocalContextManager
    at com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory.create(AsynchronousJiraRestClientFactory.java:35)
    at com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory.createWithBasicHttpAuthentication(AsynchronousJiraRestClientFactory.java:42)
    at ExampleCreateIssuesAsynchronous.main(ExampleCreateIssuesAsynchronous.java:25)
Caused by: java.lang.ClassNotFoundException: com.atlassian.sal.api.executor.ThreadLocalContextManager
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 3 more

 import java.net.URI;
    import java.util.Optional;

    import com.atlassian.jira.rest.client.api.JiraRestClient;
    import com.atlassian.jira.rest.client.api.domain.Issue;
    import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory;
    import com.atlassian.util.concurrent.Promise;

    public class JRC
    {
        public Issue getIssue(String issueKey) throws Exception
        {
            final URI jiraServerUri = new URI("stajtest.atlassian.net");
            final JiraRestClient restClient = new AsynchronousJiraRestClientFactory().createWithBasicHttpAuthentication(jiraServerUri, "stajtest***", "********");
            @SuppressWarnings("rawtypes")
            Promise issuePromise = restClient.getIssueClient().getIssue(issueKey);
            return Optional.ofNullable((Issue) issuePromise.claim()).orElseThrow(() -> new Exception("No such issue"));
        }
    }

    import static org.hamcrest.CoreMatchers.is;
    import static org.junit.Assert.assertThat;

    import org.junit.Test;

    import com.atlassian.jira.rest.client.api.domain.Issue;    

public class JRCTest
    {
        private static final String jiraKey = "DEN-24";
        @Test
        public void testGetIssue() throws Exception {
            Issue issue = new JRC().getIssue(jiraKey);
            assertThat(issue.getKey(), is(jiraKey));
        }
    }

编辑2

Edit 2

[INFO]扫描项目... [INFO]
[INFO]构建jrjc 1.0-SNAPSHOT [INFO] [INFO] [INFO] --- maven-resources-plugin:2.6:resources (默认资源)@ jrjc --- [警告]使用平台编码 (实际上是cp1254)复制已过滤的资源,即build与平台有关! > [INFO]正在复制0个资源[INFO] [INFO]- maven-compiler-plugin:3.1:compile(默认编译)@ jrjc [INFO]检测到更改-重新编译模块! [警告]尚未使用平台编码Cp1254设置文件编码,即build取决于平台! [INFO]将1个源文件编译为 C:\ Users \ Madara \ workspace \ jrjc-master \ target \ classes [错误]编译错误 [错误]/C:/Users/Madara/workspace/jrjc-master/src/main/java/JRC.java:[17,81] -source 1.5不支持lambda表达式(请使用-source 8 或更高版本以启用lambda表达式)[INFO] 1个错误[INFO] -------------------------------------------------- ----------- [INFO] ------------------------------------ ------------------------------------ [INFO]内置失败[INFO] [INFO]总时间:0.970 s [INFO]完成于: 2016-07-04T19:37:26 + 03:00 [INFO]最终内存:11M/245M [INFO] [错误]无法执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (默认编译)在项目jrjc上:编译失败[ERROR] /C:/Users/Madara/workspace/jrjc-master/src/main/java/JRC.java:[17,81] -source 1.5 [ERROR]中不支持lambda表达式(使用 -source 8或更高版本以启用lambda表达式) [错误]-> [帮助1] [错误] [错误]要查看的完整堆栈跟踪 错误,重新运行 使用-e开关进行Maven操作. [错误]使用-X开关重新运行Maven, 启用完整的调试日志记录. [错误] [错误]有关更多信息 有关错误和可能的解决方案,请阅读以下内容 文章:[错误] [帮助1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

[INFO] Scanning for projects... [INFO]
[INFO] Building jrjc 1.0-SNAPSHOT [INFO] [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ jrjc --- [WARNING] Using platform encoding (Cp1254 actually) to copy filtered resources, i.e. build is platformdependent! > [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ jrjc [INFO] Changes detected - recompiling the module! [WARNING] File encoding has not been set, using platform encoding Cp1254, i.e. build is platform dependent! [INFO] Compiling 1 source file to C:\Users\Madara\workspace\jrjc-master\target\classes [ERROR] COMPILATION ERROR [ERROR] /C:/Users/Madara/workspace/jrjc-master/src/main/java/JRC.java:[17,81] lambda expressions are not supported in -source 1.5 (use -source 8 or higher to enable lambda expressions) [INFO] 1 error [INFO] ------------------------------------------------------------- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] [INFO] Total time: 0.970 s [INFO] Finished at: 2016-07-04T19:37:26+03:00 [INFO] Final Memory: 11M/245M [INFO] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project jrjc: Compilation failure [ERROR] /C:/Users/Madara/workspace/jrjc-master/src/main/java/JRC.java:[17,81] lambda expressions are not supported in -source 1.5 [ERROR] (use -source 8 or higher to enable lambda expressions) [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

推荐答案

您从哪里获得有关API的信息? Atlassian上的文档已过时.

Where did you get the info about the API? The docs on atlassian are outdated.

首先,您的pom.xml应该如下所示:

First of all your pom.xml should look like this:

<?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>com.company</groupId>
<artifactId>jrjc</artifactId>
<version>1.0-SNAPSHOT</version>


<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>1.5</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>1.9</version>
    </dependency>
    <dependency>
        <groupId>com.atlassian.jira</groupId>
        <artifactId>jira-rest-java-client-api</artifactId>
        <version>3.0.0</version>
    </dependency>
    <dependency>
        <groupId>com.atlassian.jira</groupId>
        <artifactId>jira-rest-java-client-core</artifactId>
        <version>3.0.0</version>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>14.0-rc1</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.jettison</groupId>
        <artifactId>jettison</artifactId>
        <version>1.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.6.4</version>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.4</version>
    </dependency>
</dependencies>

<repositories>
    <repository>
        <id>atlassian-public</id>
        <url>https://m2proxy.atlassian.com/repository/public</url>
        <snapshots>
            <enabled>true</enabled>
            <updatePolicy>daily</updatePolicy>
            <checksumPolicy>warn</checksumPolicy>
        </snapshots>
        <releases>
            <enabled>true</enabled>
            <checksumPolicy>warn</checksumPolicy>
        </releases>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>atlassian-public</id>
        <url>https://m2proxy.atlassian.com/repository/public</url>
        <releases>
            <enabled>true</enabled>
            <checksumPolicy>warn</checksumPolicy>
        </releases>
        <snapshots>
            <checksumPolicy>warn</checksumPolicy>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

尝试先更改pom,看看是否可以解决.您可以在此处看到完整的示例: https://github.com/somaiah/jrjc

Try changing your pom first to see if this fixes it. You can see a fully working sample here: https://github.com/somaiah/jrjc

这篇关于JIRA使用Java创建问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆