简体   繁体   中英

java.lang.NoClassDefFoundError: org/apache/http/conn/scheme/SchemeSocketFactory

I am tring to send mail by AWSCredentials but getting an exception

java.lang.NoClassDefFoundError: org/apache/http/conn/scheme/SchemeSocketFactory

I have added these jar:

  • aws-java-sdk-1.3.11.jar
  • aws-java-sdk-1.3.11-javadoc.jar
  • aws-java-sdk-1.3.11-sources.jar
  • aws-java-sdk-flow-build-tools-1.3.11.jar
  • commons-logging.jar
  • httpclient-4.0-alpha4.jar
  • httpcore-4.0-alpha6.jar
  • log4j-1.2.13.jar
  • mail.jar

My java code is -

 import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient;
import com.amazonaws.services.simpleemail.model.*;
import java.util.LinkedList;

public class SESExample {
public static final String ACCESS_KEY = "My Access";
public static final String SECRET_KEY = "My Secret";

public static void main(String args[]) {
    String sender = "support@brandzter.com"; // should be verified email

    LinkedList<String> recipients = new LinkedList<String>();
    recipients.add("khoyendra@globussoft.com"); // again a verified email, if you are in sandbox

    SendMail(sender, recipients, "Hi", "Hi how are u?");
}

public static void SendMail(String sender, LinkedList<String> recipients, String subject, String body) {
    Destination destination = new Destination(recipients);

    Content subjectContent = new Content(subject);
    Content bodyContent = new Content(body);
    Body msgBody = new Body(bodyContent);
    Message msg = new Message(subjectContent, msgBody);

    SendEmailRequest request = new SendEmailRequest(sender, destination, msg);

    AWSCredentials credentials = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY);
    AmazonSimpleEmailServiceClient sesClient = new AmazonSimpleEmailServiceClient(credentials);
    SendEmailResult result = sesClient.sendEmail(request);

    System.out.println(result);
}

}

I am also trying to search this jar but not getting. Am I using wrong jar not sure. can any one tell me what is the problem?

I am

From the javadocs , the SchemeSocketFactory class is only available since version 4.1. So this might have something to do with the fact that you are using the 4.0 alpha jars. Try upgrading your http-client library to 4.1 or higher.

From the javadoc , it seems that the org/apache/http/conn/scheme/SchemeSocketFactory class exists since the 4.1 version.

So, try to upgrade httpclient jar to at least 4.1 version.

If you download the latest aws java SDK (I just downloaded aws-java-sdk-1.9.3),

the required libraries will be in the third-party/**/lib folders. There are a bunch of them!

This answer from jomofrodo needs more atention. Nailed it. Thanks!

In my case, I had two libraries that I created in Netbeans 7.2: one for the Apache Commons Codec 1.6, and one for the Apache Commons HttpClient 4.2.2. In this case, because the library I made for HttpClient also contained the Codec 1.6 jar, I was getting this same error.

Be sure you don't have two of the same libraries referenced in your class path, or two conflicting versions of the same library.

debug your code and point out where Exception occur. Any of instance of class that you used is not included in your jar file i think so. am not sure. find that by debugging. i think SchemeSocketFactory is not exsisting in your class path. please check

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM