使用twillo应用程序使用java发送短信时出错

使用twillo应用程序使用java发送短信时出错,java,sms,twilio,noclassdeffounderror,twilio-api,Java,Sms,Twilio,Noclassdeffounderror,Twilio Api,我正在尝试使用Twillo应用程序从java web应用程序发送短信。但是我在Glassfish服务器4.1.1上遇到以下错误 java.lang.NoClassDefFoundError: org/apache/http/conn/HttpClientConnectionManager 在 我在我的netbeans ide库文件夹中添加了Twilio 7.41.2 jar。但我 没有在pom.xml中添加任何maven依赖项,因为项目中没有启用maven,这是由于缺少maven依赖项

我正在尝试使用Twillo应用程序从java web应用程序发送短信。但是我在Glassfish服务器4.1.1上遇到以下错误

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

我在我的netbeans ide库文件夹中添加了Twilio 7.41.2 jar。但我 没有在pom.xml中添加任何maven依赖项,因为项目中没有启用maven,这是由于缺少maven依赖项导致的错误吗

  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){


  }
  }
index.jsp
Servlet sms.java
导入com.twilio.twilio;
导入com.twilio.rest.api.v2010.account.Message;
导入com.twilio.type.PhoneNumber;
导入java.io.IOException;
导入java.io.PrintWriter;
导入javax.servlet.ServletException;
导入javax.servlet.http.HttpServlet;
导入javax.servlet.http.HttpServletRequest;
导入javax.servlet.http.HttpServletResponse;
受保护的void doPost(HttpServletRequest请求、HttpServletResponse
响应)抛出ServletException、IOException{
PrintWriter out=response.getWriter();
试一试{
最终字符串帐户\u SID=“myaccountsid”;
final String AUTH_TOKEN=“my String authtoken”;
init(帐户SID、身份验证令牌);
Message Message=Message.creator(新电话号码(“收件人电话号码”),
新电话号码(“收件人电话号码”),“你好,我是汤姆”).create();
out.println(message.getSid());
processRequest(请求、响应);
}
捕获(IOException | ServletException e){
}
}

非常感谢您的帮助。

您是否将
Apache HttpClient库添加到了项目路径中?在这种情况下,我认为你不是

如果类在编译时存在,但在运行时java类路径中不可用,则会出现
NoClassDefFoundError
。通常情况下,当您得到

NoClassDefFoundError:线程“main”中出现异常 java.lang.NoClassDefFoundError

所以根据你的错误

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

您缺少Apache HttpClient库

因此,请在项目库中添加
.jar
文件。您可以从Maven存储库下载这个
jar
文件


注意:要使用twilio运行此应用程序,我想您需要根据需要添加更多库。如果您的应用程序在添加
Apache HttpClient库之后再次抛出错误,请选中此项以了解需要向项目中添加哪些库。好的,谢谢……很抱歉,您的评论太晚了。。我正在添加您提到的jar文件..让我们看看
  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){


  }
  }