gpt4 book ai didi

java - Rest FB 在 Servlet 中抛出异常

转载 作者:行者123 更新时间:2023-12-01 21:59:50 25 4
gpt4 key购买 nike

我在项目中遇到一个非常基本的问题。

我想获取 Facebook 中用户的好友列表,为此我使用了名为 RestFb 的 API(已找到 here

现在开始编码,我已经成功创建了一个名为 getFriends() 的函数,其格式如下:

public List<User> getFriends(String APP_ID, String APP_SECRET, String CODE){
//APP_ID -> Application Id generated in Facebook
//APP_SECRET -> Secret that you get from Facebook when you create the APP
//CODE -> A key that is sent to your servlet/callback url when you successfully logs in Fb with all the permissions given to App
}

该函数是一个静态函数,可以从任何地方调用。现在,当我在回调中从 Facebook 获取代码后调用此函数时,使用 main 函数,它可以工作并为我提供该应用程序的所有用户,这些用户都是我的 friend 。但是当我创建一个 servlet 并尝试调用此函数时,它会抛出此错误:

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet execution threw an exception
root cause

java.lang.NoClassDefFoundError: com/restfb/FacebookClient
com.av.test.GetFriendList.doPost(GetFriendList.java:45)
com.av.test.GetFriendList.doGet(GetFriendList.java:31)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause

java.lang.ClassNotFoundException: com.restfb.FacebookClient
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
com.av.test.GetFriendList.doPost(GetFriendList.java:45)
com.av.test.GetFriendList.doGet(GetFriendList.java:31)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

我在 Eclipse 中创建了这个项目,并使用 Eclipse 的添加外部 Jars 选项添加了 RestFb 的 Jar。我很困惑该怎么办?

代码如下:GetFriendListMain.java

public class GetFriendListMain{
public static List<User> getFriends(String APP_ID, String APP_SECRET, String CODE) throws Exception{
//code goes here
}
}

这是我的 servlet。

GetFriendList.java

public class GetFriendList extends HttpServlet {
//doGet()
public void doPost(...){
String CODE = request.getParameter("code");
String APP_ID = Config.APP_ID;
String APP_SECRET = Config.APP_SECRET;
List<User> users = GetFriendListMain.getFriends(APP_ID,APP_SECRET,CODE);
//send this list back to caller to show on webpage
}
}

请帮助我。提前致谢。:)

最佳答案

您是否尝试过在部署程序集中添加所需的存档文件?

https://www.genuitec.com/products/myeclipse/learning-center/basics/myeclipse-deployment-assembly/

或者您也可以使用像 apache maven 这样的构建工具,并将所需的存档添加为依赖项。

关于java - Rest FB 在 Servlet 中抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33750192/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com