【问题标题】:Sendgrid Java Not working in MavenSendgrid Java 在 Maven 中不起作用
【发布时间】:2015-05-17 06:54:14
【问题描述】:

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

java.lang.NoClassDefFoundError: org/apache/http/impl/client/HttpClientBuilder com.sendgrid.SendGrid.<init>(SendGrid.java:80) 我正在使用 Maven。有没有人在maven中尝试过这个。我尝试联系 sendgrid 支持团队,但仍然没有得到任何关于此的更新。谁能告诉我的代码有什么问题。提前致谢。

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

【问题讨论】:

  • 嗨,您找到解决方案了吗?它是一个Android项目吗?我在这里遇到了类似的问题..谢谢!

标签: java api maven sendgrid


【解决方案1】:

是的,我找到了解决方案。转到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 文件中。它会正常工作的。

【讨论】:

    猜你喜欢
    • 2018-05-02
    • 2016-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-27
    • 1970-01-01
    • 2014-05-21
    相关资源
    最近更新 更多