title: How to add attachment to an existing JIRA Issue using rest-client API
body: <p>I could create a jira issue using the rest client API, but i wasn't able to attach the screeshot/attachment to the exsiting <code>JIRA</code> issue. Would be really helpful if anyone could provide a solution which would be really appreciated.</p>
  
  <p>I just wrote the below code snippet for attaching a jpeg file to the existing <code>JIRA Issue</code>. But then i experienced "Exception in thread "main" <code>java.lang.NoClassDefFoundError: org/apache/commons/httpclient/HttpConnectionManager"</code> </p>
  
  <p>Code Snippet :-</p>
  
  <p>private static String addAttachment(String attachmentfilepath) throws URISyntaxException, FileNotFoundException{</p>
  
  <pre><code>    final java.net.URI jiraServerUri = new java.net.URI("https://oliveits.atlassian.net");
      FileInputStream fileStreamPath = new FileInputStream(attachmentfilenamepath);
      JerseyJiraRestClientFactory factory = new JerseyJiraRestClientFactory();
      NullProgressMonitor pm = new NullProgressMonitor();
      System.out.println("Server Url  :"+jiraServerUri);
      JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri,"mobileqa","MobileQA1234");
      Issue issue1 = restClient.getIssueClient().getIssue(newKey, pm);
      final java.net.URI AttachmentUri = new java.net.URI(jiraServerUri+"/rest/api/2/issue/"+newKey+"/attachments");
      System.out.println("URI    :"+issue1.getAttachmentsUri());
      //restClient.getIssueClient().addAttachment(pm,issue1.getAttachmentsUri(), fileStreamPath , imageName);
      restClient.getIssueClient().addAttachment(pm, AttachmentUri, fileStreamPath, imageName);
      return attachmentfilepath;
  }
  </code></pre>
  
  <p>Exception:-</p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/httpclient/HttpConnectionManager
  at com.atlassian.jira.rest.client.internal.jersey.JerseyJiraRestClientFactory.create(JerseyJiraRestClientFactory.java:34)
  at com.atlassian.jira.rest.client.internal.jersey.JerseyJiraRestClientFactory.createWithBasicHttpAuthentication(JerseyJiraRestClientFactory.java:39)
  at com.jtricks.JTricksRESTClient.addAttachment(JTricksRESTClient.java:157)
  at com.jtricks.JTricksRESTClient.main(JTricksRESTClient.java:101)
  Caused by: java.lang.ClassNotFoundException: org.apache.commons.httpclient.HttpConnectionManager
  at java.net.URLClassLoader$1.run(Unknown Source)
  at java.net.URLClassLoader$1.run(Unknown Source)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(Unknown Source)
  at java.lang.ClassLoader.loadClass(Unknown Source)
  at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
  at java.lang.ClassLoader.loadClass(Unknown Source)
  ... 4 more
  </code></pre>
  
  <p>Just added the missing jar files to the classpath. But I'm getting an exception as mentioned below.</p>
  
  <p>Exception Msg-1: com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java class com.sun.jersey.multipart.MultiPart, and Java type class com.sun.jersey.multipart.MultiPart, and MIME media type multipart/form-data; boundary=Boundary_1_18541827_1358346116249 was not found </p>
  
  <p>Exception Msg-2: com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java class com.sun.jersey.multipart.MultiPart, and Java type class com.sun.jersey.multipart.MultiPart, and MIME media type multipart/form-data; boundary=Boundary_1_18541827_1358346116249 was not found </p>