2014-03-28 52 views
2

我正在使用GWT的類項目,雖然一切工作之前,我最近重構我的代碼,突然間我跑進入標題錯誤。我四處搜索,看起來GWTBridge問題是由兩個主要原因造成的:a)修正爲2.5.1的錯誤,或者b)嘗試從服務器調用客戶端代碼,反之亦然(classNotFoundException GWTBridge)。GWT錯誤:java.lang.NoClassDefFoundError:com /谷歌/ gwt /核心/客戶端/ GWTBridge

我正在使用GWT 2.5.1,我99%確定我沒有違反b),所以我很茫然。我簡直就是在重構時從工作版本複製粘貼代碼,所以我不確定問題來自哪裏。

我的直覺是,它可能與我在重構時創建的兩個靜態Singleton類有關。重構時的我的目標僅僅是讓RPC更不混亂,因爲它迫使我鏈接一堆異樣的調用,這使得我瘋狂。我基本上做的是創建兩個靜態的Singleton類(PageLoader和UserManager),它們的目的是進行異步調用並返回返回的任何OnSuccess,這樣在onModuleLoad中我可以進行連續的RPC調用而不必處理鏈接(例如,我可以只需進入UserManager.getInstance()。isLoggedIn(),然後在稍後的RPC調用中使用返回的布爾值,而不必將該調用放入onSuccess函數中。我將這兩個類與我的Async類放在client.services中。

我不知道爲什麼這可能會導致一個問題,但我想不出別的。知道我是否在正確的軌道上?

我已經附加了下面的一個靜態類和部分返回的堆棧跟蹤。


的UserManager類

package com.google.gwt.sample.vendorcouver.client.services; 

import com.google.gwt.core.client.GWT; 
import com.google.gwt.sample.vendorcouver.client.user.VenUser; 
import com.google.gwt.user.client.Window; 
import com.google.gwt.user.client.rpc.AsyncCallback; 


/*Singleton that simplifies making asynchronous calls to the server side.*/ 

public class UserManager { 

    private static UserManager UserManagerInstance = null; 
    private static LoginServiceAsync LoginServiceInstance = null; 
    private static VenUserServiceAsync VenUserServiceInstance = null; 
    private static boolean isLoggedIn = false; 
    private static boolean isAdmin = false; 
    private static String UserName = null; 


    public static UserManager getInstance() 
    { 
     if (UserManagerInstance == null) 
     { 
      UserManagerInstance = new UserManager(); 
      LoginServiceInstance = GWT.create(LoginService.class); 
      VenUserServiceInstance = GWT.create(VenUserService.class); 
     } 
     return UserManagerInstance; 
    } 

    public boolean isLoggedIn() 
    { 
     LoginServiceInstance.isLoggedIn(new AsyncCallback<Boolean>() { 
      public void onFailure(Throwable error) { 
       Window.alert("Sorry, there seemed to be an error on the server side! You may be unable to log in."); 
      } 
      public void onSuccess(Boolean loggedInStatus) { 
       Window.alert("isLoggedIn is sucessful; will return" + loggedInStatus); 
       isLoggedIn = loggedInStatus; 
      } 
     }); 
     return isLoggedIn; 
    } 

堆棧跟蹤:

SEVERE: javax.servlet.ServletContext log: Exception while dispatching incoming RPC call 
com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract boolean com.google.gwt.sample.vendorcouver.client.services.LoginService.isLoggedIn()' threw an unexpected exception: java.lang.NoClassDefFoundError: com/google/gwt/core/client/GWTBridge 
    at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:389) 
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:579) 
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208) 
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248) 
    at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166) 
    at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:123) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:366) 
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:349) 
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388) 
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) 
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) 
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) 
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418) 
    at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:97) 
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) 
    at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:487) 
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) 
    at org.mortbay.jetty.Server.handle(Server.java:326) 
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) 
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938) 
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755) 
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218) 
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) 
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409) 
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582) 
Caused by: java.lang.NoClassDefFoundError: com/google/gwt/core/client/GWTBridge 
    at com.google.gwt.user.client.Window.<clinit>(Window.java:504) 
    at java.lang.Class.forName0(Native Method) 
    at java.lang.Class.forName(Unknown Source) 
    at com.google.appengine.tools.development.agent.runtime.RuntimeHelper.checkRestricted(RuntimeHelper.java:70) 
    at com.google.appengine.tools.development.agent.runtime.Runtime.checkRestricted(Runtime.java:64) 
    at com.google.gwt.sample.vendorcouver.server.LoginServiceImpl.isLoggedIn(LoginServiceImpl.java:17) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:115) 
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:561) 
    ... 40 more 
Caused by: java.lang.ClassNotFoundException: com.google.gwt.core.client.GWTBridge 
    at java.net.URLClassLoader$1.run(Unknown Source) 
    at java.net.URLClassLoader$1.run(Unknown Source) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(Unknown Source) 
    at java.lang.ClassLoader.loadClass(Unknown Source) 
    at com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:216) 
    at java.lang.ClassLoader.loadClass(Unknown Source) 
    ... 52 more 

回答

3

堆棧跟蹤是明確的:你想使用com.google.gwt.user.client.Window(客戶端)類從com.google.gwt.sample.vendorcouver.server.LoginServiceImpl#isLoggedIn(服務器端代碼)


順便說一句,你確實知道你的UserManager#isLoggedIn總是返回false第一次叫它吧? (由於RPC調用的異步特性)

+0

啊,你是對的!我沒有意識到這會是一個問題。你可以擴展你的第二個評論嗎?我不明白爲什麼isLoggedIn()總是返回false。爲什麼RPC調用是異步的,首先它總是返回false? – aquariuz

+0

當你第一次調用'isLoggedIn()'時,你發出一個異步的RPC請求,並且由於它是異步的,控制在響應返回之前返回'isLoggedIn()',所以'return isLoggedIn'返回初始值'isLoggedIn',它是'false'。然後幾毫秒後,響應從服務器返回並更新'isLoggedIn'(假設爲'true')。下一次調用'isLoggedIn()',你創建一個新的RPC並返回'isLoggedIn'的_previous_值(即'true'),然後幾毫秒後響應到達並更新'isLoggedIn'。 –

0

添加下面的項目中的(確保包是正確的):

package com.google.gwt.core.client; 
import com.google.gwt.core.shared.*; 
/** 
* Date: 1/17/13 
* Time: 12:37 PM 
* This class is used for fixing class not found com.google.gwt.core.client.GWTBridge; 
* 
* This is only needed for GXT 2 to work. Once we remove GXT2, this can be removed also. 
*/ 
public abstract class GWTBridge extends com.google.gwt.core.shared.GWTBridge { 
} 

原文:http://alexluca.com/2013/01/17/gwt-25-and-extgwt-224-classnotfoundexception-comgooglegwtcoreclientgwtbridge/

0

Window.alert的,也不允許在服務器端。