gpt4 book ai didi

java - Sendgrid Java 在 Maven 中不工作

转载 作者:行者123 更新时间:2023-11-30 11:03:40 25 4
gpt4 key购买 nike

我正在使用 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);
}

最佳答案

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

关于java - Sendgrid Java 在 Maven 中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30284213/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com