0

I am trying to send SMS from java web application using Twillo app. But I am getting the following error at Glassfish server 4.1.1

 java.lang.NoClassDefFoundError: 
 org/apache/http/conn/HttpClientConnectionManager 

at

 Message message = Message.creator(new PhoneNumber(""),

I have added Twilio 7.41.2 jar in my netbeans ide library folder. But I have not added any maven dependency in pom.xml as this is not maven enabled the project, is this the error due to missing maven dependency?

  index.jsp

  <form action="sms" method="post">
  <input type ="submit"/>
  </form>

  Servlet sms.java

  import com.twilio.Twilio;
  import com.twilio.rest.api.v2010.account.Message;
  import com.twilio.type.PhoneNumber;
  import java.io.IOException;
  import java.io.PrintWriter;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;

  protected void doPost(HttpServletRequest request, HttpServletResponse 
  response) throws ServletException, IOException {
  PrintWriter out = response.getWriter();

  try{

  final String ACCOUNT_SID = "myaccountsid";
  final String AUTH_TOKEN = "my string authtoken";

  Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

  Message message = Message.creator(new PhoneNumber("recipient phone no"),
  new PhoneNumber("recipient phone no"),"Hello This is Tom").create();

  out.println(message.getSid());


    processRequest(request, response);

    }
 catch(IOException | ServletException e){


  }
  }

Any help is much appreciated.

Hasitha Jayawardana
  • 2,326
  • 4
  • 18
  • 36
Tom
  • 761
  • 7
  • 22
  • 41

1 Answers1

0

Did you add the Apache HttpClient Library to your project path? In this case, I think you are not.

NoClassDefFoundError will come if a class was present during compile time but not available in java classpath during runtime. Normally you will see below line in log when you get,

NoClassDefFoundError: Exception in thread "main" java.lang.NoClassDefFoundError

So according to your error,

java.lang.NoClassDefFoundError: org/apache/http/conn/HttpClientConnectionManager

you are missing the Apache HttpClient Library.

So please add the .jar file in your project library. You can download this jar file from the Maven Repository.

Download from Maven Repository

Note: To run this application with twilio I guess you need to add more libraries according to the Twilio Documentation. Check this GitHub link to get know about what libraries need to add to the project if your application throws error again after adding the Apache HttpClient Library.

Hasitha Jayawardana
  • 2,326
  • 4
  • 18
  • 36
  • Ok thanks ...sorry for late comment.. i am adding your mentioned jar file..lets see – Tom Aug 30 '19 at 16:19