`
witcheryne
  • 浏览: 1094413 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

Gxt2.1中使用Gwt2.0开发模式.初探.java.lang.VerifyError问题解决

阅读更多

    前两天看见Gwt2.0发布的消息,新的特性让人相当兴奋,尤其是开发者模式,大大提高了调试效率。随即就将项目升级到了Gwt2.0+Gxt2.1, 并且eclipse也更新到最新的1.2..  

    安装插件,运行代码,一路基本都没有问题。。  在开发者模式下访问host page...  碰到如下错误:

 

    错误信息 写道

17:03:39.250 [ERROR] [webim] Unable to load module entry point class st.lv.web.im.client.WebIM (see associated exception for details)
java.lang.VerifyError: (class: com/extjs/gxt/ui/client/widget/Container, method: adjustIndex signature: (Lcom/extjs/gxt/ui/client/widget/Component;I)I) Illegal constant pool index
at com.extjs.gxt.ui.client.widget.MessageBox.getDialog(MessageBox.java:339)
at com.extjs.gxt.ui.client.widget.MessageBox.show(MessageBox.java:737)
at com.extjs.gxt.ui.client.widget.MessageBox.alert(MessageBox.java:104)
at st.lv.web.im.client.WebIM.onModuleLoad(WebIM.java:18)
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.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:369)
at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:185)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:380)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:222)
at java.lang.Thread.run(Unknown Source

     经过一番google也没查出什么原因, 用一段很简单的代码调试追踪(代码如下:),发现是devMode反射的时候出的问题,虽然知道问题的大致原因,但是还是没办法解决。

     package st.lv.web.im.client;


import com.google.gwt.core.client.EntryPoint;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class WebIM implements EntryPoint {

	
	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		
//		com.google.gwt.user.client.Window.alert("ok..");//this line is ok..
		com.extjs.gxt.ui.client.widget.MessageBox.alert("gxt", "gxt", null);
	}
}

 

    最后只得求助ext的官方论坛, 最终将这段代码跑通解决了。。

http://www.extjs.com/forum/showthread.php?p=420100#post420100post420100

 

    经tortexy解释: 该原因是由Class Loader产生的,当com.extjs.gxt.ui.client.widget.Layout加载太晚,classloader将停止执行。

 

   最终代码如下所示:

package st.lv.demo.overview.client;

import com.extjs.gxt.ui.client.widget.Layout;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.layout.AnchorLayout;
import com.google.gwt.core.client.EntryPoint;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Gwt2Gxt implements EntryPoint {

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {		
		
		@SuppressWarnings("unused")
		Layout junk = new AnchorLayout();//提前初始化Layout对象
		MessageBox.alert("Msg", "gxt MessageBox", null);	
	}
}

 

    虽然这个问题解决了,但是项目在Gxt2.1+Gwt2.0的Develop Mode下还是会报很多错误,依然没有升级到Gwt2.0...  不过在Gxt的论坛上并没有太多设计关于Gxt2.1中使用Gwt2.0新特性的问题,看来这些东西又得自己开始慢慢摸索了。。。

分享到:
评论
10 楼 angjunwen 2010-01-13  
GWT 和spring security 整合的问题终于在昨天解决了,最终还是参考 code google 上 dmartin.pro 的 gwt-incubator-security 来完成的,不过 gwt-incubator-security 有个小问题 ,里面用到的 transmorph.jar 好像不能使用最新版本的。
9 楼 angjunwen 2010-01-12  
如果不整合spring security 我目前还没遇到什么问题。谢谢你的回答!
8 楼 witcheryne 2010-01-12  
angjunwen 写道
gwt-incubator-lib 这个我也看过,但是我没有找到使用它开发的实例,其实spring security 官方提供的例子中有整合GWT的,但是那只是在JSP文件中引入GWT 的相关组件,不是一个纯粹的 GWT 应用。有关GWT 和 spring security 整合的例子我也看过几个,但都不是单纯的GWT 应用,我现在准备做的是一个单纯用GWT+GXT 做前台表现的应用。gwt-incubator-lib 只是在 GWT-SL的基础上进行了一些封装(个人认为)。我不知道你那个应用是不是用单纯的gwt做表现层的 ?


我们项目也是在用Gwt + Gxt,通过RPC调用和后台交互... 

spring security好像没用到,整合这方面可能没办法帮你...

关于是否在jsp文件中引入GWT组件, 这个应该没有什么影响吧···
gwt中的html页面也只是引用编译后的js文件而已,只要页面能引用js就行。。。
7 楼 angjunwen 2010-01-12  
http://www.javaworld.com.tw/jute/post/view?bid=49&id=251825 这里有个 GWT+Spring+Spring Security+Hibernate  的例子,但是他也是在JSP 中引入 GWT .使用了 GWT-SL.JAR .
6 楼 angjunwen 2010-01-12  
gwt-incubator-lib 这个我也看过,但是我没有找到使用它开发的实例,其实spring security 官方提供的例子中有整合GWT的,但是那只是在JSP文件中引入GWT 的相关组件,不是一个纯粹的 GWT 应用。有关GWT 和 spring security 整合的例子我也看过几个,但都不是单纯的GWT 应用,我现在准备做的是一个单纯用GWT+GXT 做前台表现的应用。gwt-incubator-lib 只是在 GWT-SL的基础上进行了一些封装(个人认为)。我不知道你那个应用是不是用单纯的gwt做表现层的 ?
5 楼 witcheryne 2010-01-12  
angjunwen 写道
能否把你项目关于gwt和spring security 整合如何整合的讲解下?

代买我贴出来,不知道是不是你需要的...
import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.context.WebApplicationContext;

import cn.com.dayang.common.user.domain.RemoteUser;
import cn.com.dayang.common.user.domain.User;
import cn.com.dayang.common.user.webwork.interceptor.LoginInterceptor;

import com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.SerializationException;
import com.google.gwt.user.server.rpc.RPC;
import com.google.gwt.user.server.rpc.RPCRequest;
import com.google.gwt.user.server.rpc.RPCServletUtils;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.google.gwt.user.server.rpc.SerializationPolicy;

/**
 * @author Zwf
 * 
 */
public class MyGWTServer extends RemoteServiceServlet {
	

	private final ThreadLocal<HttpServletRequest> perThreadRequest = new ThreadLocal<HttpServletRequest>();
	private final ThreadLocal<HttpServletResponse> perThreadResponse = new ThreadLocal<HttpServletResponse>();

	private WebApplicationContext springContext;

	@Override
	public void init(ServletConfig Config) throws ServletException {
		super.init(Config);
		springContext = (WebApplicationContext) Config.getServletContext().getAttribute(
				WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);

		if (springContext == null) {
			throw new RuntimeException("Check Your Web.Xml Setting, No Spring Context Configured");
		}

	}

	@Override
	protected SerializationPolicy doGetSerializationPolicy(HttpServletRequest request, String moduleBaseURL,
			String strongName) {
		return super.doGetSerializationPolicy((HttpServletRequest) perThreadRequest.get(), moduleBaseURL, strongName);
	}

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		try {
			
			perThreadRequest.set(req);
			perThreadResponse.set(resp);
	
			String requestURI = req.getRequestURI();
			String beanname = requestURI.substring(requestURI.lastIndexOf("/") + 1,requestURI.lastIndexOf(".gwt"));
			RemoteService service = (RemoteService) springContext.getBean(beanname);

			String requestPayload = readPayloadAsUtf8(req);
			
			// Let subclasses see the serialized request.
			//    
			onBeforeRequestDeserialized(requestPayload);

			// Invoke the core dispatching logic, which returns the serialized
			// result.
			//    
			 HttpSession session=req.getSession(true);
			 if(session.getAttribute(LoginInterceptor.USER_LOGIN)==null)
			{
			System.out.println("no user login!!!!!");
				throw new Exception("please login");
			}
			 User user = (User)session.getAttribute(LoginInterceptor.USER_LOGIN);
			 RemoteUser.set(user);
			String responsePayload = processCall(service, requestPayload);

			// Let subclasses see the serialized response.
			//    
			onAfterResponseSerialized(responsePayload);

			// Write the response.
			//    
			writeResponse(req, resp, responsePayload);
		} catch (Throwable e) {
			// Give a subclass a chance to either handle the exception or
			// rethrow it
			//    
			doUnexpectedFailure(e);
		} finally {
			// HttpRequestContext.ThreadLocalHttpRequestContext.remove();
			perThreadRequest.set(null);
			perThreadResponse.set(null);
		}
	}

	/**
	 * rewrite processCall
	 * 
	 * @param bean
	 * @param payload
	 * @return
	 * @throws SerializationException
	 */
	public String processCall(RemoteService bean, String payload) throws SerializationException {
		try {			
			RPCRequest rpcRequest = RPC.decodeRequest(payload, bean.getClass(), this);
			return RPC.invokeAndEncodeResponse(bean, rpcRequest.getMethod(), rpcRequest.getParameters(), rpcRequest
					.getSerializationPolicy());
		} catch (IncompatibleRemoteServiceException ex) {
			getServletContext().log("An IncompatibleRemoteServiceException was thrown while processing this call.", ex);
			return RPC.encodeResponseForFailure(null, ex);
		}
	}

	private String readPayloadAsUtf8(HttpServletRequest request) throws IOException, ServletException {
		return RPCServletUtils.readContentAsUtf8(request, true);
	}

	private void writeResponse(HttpServletRequest request, HttpServletResponse response, String responsePayload)
			throws IOException {
		boolean gzipEncode = RPCServletUtils.acceptsGzipEncoding(request)
				&& shouldCompressResponse(request, response, responsePayload);
		RPCServletUtils.writeResponse(getServletContext(), response, responsePayload, gzipEncode);
	}
}


这个是关于Gwt Security的一个扩展...
http://code.google.com/p/gwt-incubator-lib/
相关主题可以看这里:
http://osdir.com/ml/GoogleWebToolkit/2009-02/msg01214.html
4 楼 angjunwen 2010-01-11  
能否把你项目关于gwt和spring security 整合如何整合的讲解下?
3 楼 witcheryne 2010-01-02  
angjunwen 写道
gxt2.1 和 gwt 整合真的有这么多问题吗?我近期正在准备用gwt2.0+gxt2.1+spring+spring security+hibernate+mysql 来开发一个管理平台,如果gxt2.1和gwt2.0 整合有这些问题我就要降低版本了。还有不知你们用GWT整合过springsecurity没有,在网上GOOGLE了几天只有在国外的网站上发现有人这么整过。

项目有整合spring, 这部分不是我做的... 节后上班可以给你看看。。

关于Gxt2.1和Gwt2.0兼容问题,我在官网上并没找到什么讨论文章,如果直接使用应该没什么问题。。
我们项目是从Gwt1.5+Gxt1.2.3一路走过来的,中间经历过从Gwt1.5+Gxt1.2.3到Gwt1.6+Gwt2.0,一次大的升级。可能是由于一些历史代码的原因,最近升级到Gwt2.0+Gxt2.1一直没有成功。现在项目保持Gwt1.7+Gxt2.1

不过官方解释很明确,Gxt2.1是基于Gwt2.0编译..  直接应该没什么问题..


2 楼 angjunwen 2009-12-31  
gxt2.1 和 gwt 整合真的有这么多问题吗?我近期正在准备用gwt2.0+gxt2.1+spring+spring security+hibernate+mysql 来开发一个管理平台,如果gxt2.1和gwt2.0 整合有这些问题我就要降低版本了。还有不知你们用GWT整合过springsecurity没有,在网上GOOGLE了几天只有在国外的网站上发现有人这么整过。
1 楼 toeo 2009-12-19  
对.分页的那个地方也有错误.所以要用GXT 还是用 GWT 1.7 比较好.

相关推荐

Global site tag (gtag.js) - Google Analytics