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();
}
}
}
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
Edit:
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));
}
}
Edit 2
[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