【问题标题】:SendGrid - NoClassDeffoundError using sendgrid-java.jarSendGrid - NoClassDeffoundError 使用 sendgrid-java.jar
【发布时间】:2016-05-17 03:38:45
【问题描述】:

我是第一次使用 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");

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

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

这里是例外:

    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)

我尝试在 SO,Sendgrid Java Not working in Maven 上遵循这个建议,但它也导致了同样的错误。

有什么建议吗?如果您还需要什么,请告诉我..

【问题讨论】:

标签: java eclipse maven lambda sendgrid


【解决方案1】:

我尝试了 SO 上发布的大多数解决方案,但无法正常工作。最后,我切换到使用 SendGrid4j。这在添加 httpclient、httpcore、httpmime 以及 gson、jackson-core、库后有效。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多