我在我的应用程序中使用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("[email protected]");
email.setFrom("[email protected]");
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文件中。它将正常工作。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句