I’m trying to set up a connection to my Jira instance using Java and the REST API. I’ve been exploring the Jira REST Java Client (JRJC) library, but I’ve encountered some issues along the way.
Here’s a simplified version of what I’m attempting:
import com.atlassian.jira.rest.client.api.JiraRestClient;
import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory;
public class JiraConnector {
public static void main(String[] args) {
URI jiraUrl = URI.create("http://localhost:8080/jira");
AsynchronousJiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
JiraRestClient client = factory.createWithBasicHttpAuthentication(jiraUrl, "username", "password");
// Attempt to get user and issue info
// This is where I'm getting stuck
}
}
I’ve tested multiple versions of the JRJC library (2.0.0-m2, 3.0.0, and 4.0.0) but still encounter errors. The main issue appears to be with the Promise type not being recognized correctly.
I also set up a Maven project with the required dependencies, yet my IDE still does not recognize the classes. Can anyone confirm if they’ve successfully used JRJC recently? I’d appreciate any advice on resolving these dependency issues or alternative ways to connect to Jira using Java.
I’ve faced similar challenges with the Jira REST Java Client. Instead of wrestling with JRJC, consider using the Jersey client library for a more straightforward approach. It’s well-maintained and provides robust HTTP client capabilities.
Here’s a basic example to get you started:
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://your-jira-instance/rest/api/2/issue/");
Response response = target.request(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, "Basic " + Base64.getEncoder().encodeToString("username:password".getBytes()))
.get();
String jsonResponse = response.readEntity(String.class);
This method bypasses the complexities of JRJC while still allowing you to interact with Jira’s REST API effectively. Remember to handle exceptions and close resources properly in your implementation.
hey man, i know the struggle. try using atlassian-connect-spring-boot-starter; it’s simpler and avoids those promise issues. add it to ur pom and follow their docs. might be the remedy u need.
I’ve been down this road before, and I feel your pain. The JRJC can be a real headache sometimes. Have you considered using the Apache HttpClient library instead? It’s what I ended up switching to after banging my head against the wall with JRJC for weeks.
Here’s a quick snippet that might help you get started:
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet request = new HttpGet("https://your-jira-instance.com/rest/api/2/issue/ISSUE-123");
request.addHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString("username:password".getBytes()));
HttpResponse response = httpClient.execute(request);
String json = EntityUtils.toString(response.getEntity());
This approach is more lightweight and gives you more control over the HTTP requests. Plus, it’s easier to debug when things go wrong. Just make sure to add the necessary Apache HttpClient dependencies to your pom.xml file.