gpt4 book ai didi

java - Tomcat 7 - Google Oauth2 - ClassNotFoundException - Java - Eclipse

转载 作者:行者123 更新时间:2023-11-28 23:28:09 25 4
gpt4 key购买 nike

我正在尝试离线访问我的谷歌日历。这个问题之前在这里已经回答过: Offline Access to google calendar using java但出于某种原因,我在尝试进行身份验证时总是会收到 ClassNotFoundException。

我在 Apache Tomcat 7 服务器上本地运行应用程序并使用 Eclipse Mars。我通过 Google API ManagerPlugin 安装了以下 API:

  • Google OAuth2 API v2
  • (Google OAuth API v1)插件告诉我,首选 v2
  • Google 日历 API

通常我将外部 jar 文件复制到 WEB-INF/lib 文件夹和 Tomcat/lib 文件夹,但我想插件会为我做这些,对吗?所有 API 都列在我的 JavaBuildPath 中。

如果我运行与 Java 应用程序 相同的功能,它就可以工作,所以一定是 Tomcat 设置有问题。

有没有人以前遇到过这样的问题,可以帮助我吗?提前致谢。

Servlet(删除凭据):

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
this.authenticate(request, response);
}


public void authenticate(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

String client_id = "";
String redirect_uri = "";
String scope = "https://www.googleapis.com/auth/calendar";
String client_secret = "";
List <String> scopes;
HttpTransport transport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();

scopes = new LinkedList<String>();
scopes.add(scope);
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(transport, jsonFactory, client_id, client_secret, scopes).build();
GoogleAuthorizationCodeRequestUrl url = flow.newAuthorizationUrl();
url.setRedirectUri(redirect_uri);
url.setApprovalPrompt("force");
url.setAccessType("offline");
String authorize_url = url.build();
response.sendRedirect(authorize_url);
}

控制台:

java.lang.ClassNotFoundException: com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow$Builder
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1854)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1703)
at net.meetme.CalendarServlet.authenticate(CalendarServlet.java:88)
at net.meetme.CalendarServlet.doGet(CalendarServlet.java:42)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

最佳答案

感谢您的快速回复。我将所有 jar 文件部署到我的 WEB-INF/lib。

错误是我还将所有 jar 文件添加到 Java 构建路径。您只需从构建路径中删除这些 jar- 文件即可。

关于java - Tomcat 7 - Google Oauth2 - ClassNotFoundException - Java - Eclipse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34322162/

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