HttpClient NoClassDefFoundError

Viewed 63949

I am trying to run a sample application from HttpClient 4.0.1. It is the file ClientMultiThreadedExecution.java from the examples section. I put in these files in the classpath: apache-mime4j-0.6.jar;commons-codec-1.3.jar;commons-logging-1.1.1.jar;httpclient-4.0.1.jar;httpcore-4.0.1.jar;httpmime-4.0.1.jar and the file compiles correctly. At runtime I get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/client/methods/HttpUriRequest
Caused by: java.lang.ClassNotFoundException: org.apache.http.client.methods.HttpUriRequest
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

Am I missing a reference? It seems like a classpath error but I can't figure out which jar file to include? Thank you in advance for your help.

5 Answers

I want to small improve only for Exception when you will problem with connection, sending, ... AND you want to know WAY.

httpclient-4.5.13.jar httpcore-4.5.13.jar +++ for Exception +++ javax.activation-api-1.2.0.jar javax.annotation-api-1.3.2.jar javax.xml.soap-api-1.4.0.jar jaxb-api-2.3.1.jar

public static boolean sendEmailViaExchange( String strUserName, String strPassword, String strDomain, String strURI, String strRecipient, String strSubject, String strMessageBody )  // BYTE attachment
{                   
    try  // e-mail
    {                   
        ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
        service.setCredentials(new WebCredentials(strUserName, strPassword, strDomain));
        service.setUrl( new URI( strURI ) );    

        EmailMessage msg= new EmailMessage(service);                
        msg.setSubject( strSubject );
        msg.setBody(MessageBody.getMessageBodyFromText( strMessageBody ));
        msg.getToRecipients().add( strRecipient );
        msg.send();
    }
    catch (Exception e)     // try  // e-mail   
    {
        LOGGER.log(Level.SEVERE, "ERROR: " + e.getMessage());
                
        return false;
    }   // try  // e-mail  catch (Exception e)
            
    return true;
}   //  public static boolean sendEmailViaExchange( String strUserName, String strPassword, String strDomain, String strURI, String strRecipient, String strSubject, String strMessageBody )  // BYTE attachment
Related