SendGrid - 使用sendgrid-java.jar的NoClassDeffoundError [英] SendGrid - NoClassDeffoundError using sendgrid-java.jar

查看:376
本文介绍了SendGrid - 使用sendgrid-java.jar的NoClassDeffoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次使用SendGrid。在这方面,我已经看过关于SO的其他问题,但对我来说都没有。



我正在使用Eclipse和Amazon Web Services - Lambda。
我正在使用的图书是 https://github.com/sendgrid/sendgrid-java



我的场景是,我正在使用Lambda函数向已选择电子邮件通信的用户发送电子邮件。



这是我的代码:

  Email email = new Email ); 
email.addTo(DEV_TO_EMAIL);
email.addToName(XXXXX);
email.setFrom(DEV_FROM_EMAIL);
email.setSubject(XX);
email.setText(sms_message);

尝试{
sendgrid.send(email);
} catch(SendGridException e){
e.printStackTrace();

if(DEBUG)
logger.log(发送电子邮件时异常);
}

以下是例外:

 无法初始化类

org.apache.http.impl.conn.ManagedHttpClientConnectionFactory:java.lang.NoClassDefFoundError java.lang.NoClassDefFoundError:无法初始化类org.apache.http.impl.conn.ManagedHttpClientConnectionFactory

org.apache.http.impl.conn.PoolingHttpClientConnectionManager $ InternalConnectionFactory。< init>(PoolingHttpClientConnectionManager.java:493)at

org.apache.http.impl.conn.PoolingHttpClientConnectionManager。< init>(PoolingHttpClientConnectionManager.java:149)at

org.apache.http.impl.conn.PoolingHttpClientConnectionManager。 < init>(PoolingHttpClientConnectionManager.java:138)at

org.apache.http.impl.conn.PoolingHttpClientConnectionManager。< init>(PoolingHttpClientConnectionManager.java:114)at

org.apache.http.impl.client.HttpClientBuilder.build( HttpClientBuilder.java:726)

com.sendgrid.SendGrid。< init>(SendGrid.java:71)at

xx.LambdaFunction.handleRequest(LambdaFunction.java :183)at

xx.LambdaFunction.handleRequest(LambdaFunction.java:1)

我试图按照这个建议, Sendgrid Java在Maven中不工作,但它也导致了相同的错误。



有什么建议可以做什么?让我知道,如果你需要其他任何东西..

解决方案

我尝试了大部分SO解决方案,但无法获得它工作最后,我切换到使用SendGrid4j。在添加httpclient,httpcore,httpmime以及gson,jackson-core,库之后,这样做有效。



sendgid4j的链接 - https://github.com/shunjikonishi/sendgrid4j


I am using SendGrid for the first time. I have looked at other questions on SO, in this regard, but none worked for me.

I am using Eclipse and Amazon Web Services - Lambda. The library i am using is https://github.com/sendgrid/sendgrid-java

My scenario is, i am using a Lambda function to send emails to users who have opted for email communication.

Here is my code:

                        Email email = new Email();
                        email.addTo(DEV_TO_EMAIL);
                        email.addToName("XXXXX");
                        email.setFrom(DEV_FROM_EMAIL);
                        email.setSubject("XX");
                        email.setText("sms_message");

                        try {
                            sendgrid.send(email);
                        } catch (SendGridException e) {
                            e.printStackTrace();

                            if(DEBUG)
                                logger.log("Exception while sending Email");
                        }

Here is the Exception:

    Could not initialize class 

org.apache.http.impl.conn.ManagedHttpClientConnectionFactory: java.lang.NoClassDefFoundError java.lang.NoClassDefFoundError: Could not initialize class org.apache.http.impl.conn.ManagedHttpClientConnectionFactory at 

org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.<init>(PoolingHttpClientConnectionManager.java:493) at 

org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:149) at 

org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:138) at 

org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:114) at 

org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:726) at 

com.sendgrid.SendGrid.<init>(SendGrid.java:71) at 

xx.LambdaFunction.handleRequest(LambdaFunction.java:183) at 

xx.LambdaFunction.handleRequest(LambdaFunction.java:1)

I tried to follow this suggestion on SO, Sendgrid Java Not working in Maven, but it resulted in the same error as well.

Any suggestions on what to do? Let me know if you need anything else..

解决方案

I tried most of the solutions posted on SO, but couldn't get it to work. Finally, i switched to using SendGrid4j. This worked after adding httpclient, httpcore, httpmime along with gson, jackson-core, libraries.

link for sendgid4j - https://github.com/shunjikonishi/sendgrid4j

这篇关于SendGrid - 使用sendgrid-java.jar的NoClassDeffoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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