Sendgrid Java 在 Maven 中不起作用 [英] Sendgrid Java Not working in Maven

查看:31
本文介绍了Sendgrid Java 在 Maven 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 https://github.com/sendgrid/sendgrid-java应用程序.当我尝试运行 sendgridexample.java 时,它导致错误 InvocationTargetException,根本原因是

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/HttpClientBuildercom.sendgrid.SendGrid.(SendGrid.java:80)我正在使用 Maven.有没有人在 Maven 中尝试过这个.我尝试联系 sendgrid 支持团队,但仍然没有得到任何关于此的更新.任何人都可以告诉我的代码有什么问题.提前致谢.

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);
}

推荐答案

是的,我找到了解决方案.转到 https://github.com/sendgrid/sendgrid-java/tree/master/src/main/java/com/sendgrid.复制两个 java 文件 [SendGrid.java 和 SendGridException.java] 并在您的应用程序中创建一个文件夹 com.sendgrid 并将这两个 java 文件粘贴到该文件夹​​中.然后去https://github.com/sendgrid/sendgrid-java/blob/master/pom.xml.复制这两个 java 文件的所有依赖项并粘贴到 pom.xml 文件中.它会正常工作.

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.

这篇关于Sendgrid Java 在 Maven 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆