且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Sendgrid的Java不在Maven的工作

更新时间:2022-10-17 10:14:20

是的,我已经找到了解决办法。转到 https://github.com/sendgrid / sendgrid-的Java /树/主/ src目录/主/ JAVA / COM / sendgrid 。复制两个Java文件[SendGrid.java和SendGridException.java],并创建应用程序的文件夹com.sendgrid并粘贴文件夹内这两个Java文件。然后去 https://github.com/sendgrid/sendgrid-java/ BLOB /主/ pom.xml的。复制所有这两个的Java文件的依赖性,并在你的pom.xml文件粘贴。这将正常工作。

I am using https://github.com/sendgrid/sendgrid-java in my app. When I tried to run a sendgridexample.java its causing error InvocationTargetException and the root cause is

java.lang.NoClassDefFoundError: org/apache/http/impl/client/HttpClientBuilder com.sendgrid.SendGrid.<init>(SendGrid.java:80) I am using maven. Is there anyone tried this in maven. I tried reaching the sendgrid support team but still didn't get any update regarding this. Can any one tell 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);
}

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