Sendgrid Java Doesn't Work in Maven

I am using https://github.com/sendgrid/sendgrid-java in my application. When I tried to run sendgridexample.java, causing an InvocationTargetException error, and the main reason is

java.lang.NoClassDefFoundError: org/apache/http/impl/client/HttpClientBuilder com.sendgrid.SendGrid.<init>(SendGrid.java:80) I am using maven. Has anyone tried this in maven. I tried to contact the sendgrid support team, but still have not received any update. Can someone say what is wrong with my code. Thanks in advance.

 SendGrid sendgrid = new SendGrid("API_KEY"); SendGrid.Email email = new SendGrid.Email(); email.addTo(" user@domain.com "); email.setFrom(" otheruser@domain.com "); email.setSubject("Hello World"); email.setText("My first email with SendGrid Java!"); try { SendGrid.Response response = sendgrid.send(email); System.out.println(response.getMessage()); } catch (SendGridException e) { System.err.println(e); } 
+2
source share
1 answer

Yes, I found a solution. Go to https://github.com/sendgrid/sendgrid-java/tree/master/src/main/java/com/sendgrid . Copy the two java files [SendGrid.java and SendGridException.java] and create the com.sendgrid folder in your application and paste these two java files inside this folder. Then go to https://github.com/sendgrid/sendgrid-java/blob/master/pom.xml . Copy all the dependency for these two java files and paste into your pom.xml file. It will work fine.

+1
source

Source: https://habr.com/ru/post/1433199/


All Articles