在GWT中使用GWTquery [英] Using GWTquery with GWT

查看:140
本文介绍了在GWT中使用GWTquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以告诉我如何使用GWTquery和GWT? GWTquery教程页面主要介绍如何使用jQuery,但没有太多解释如何嵌入它。例如,如果我想将它与GWT附带的默认Stockwatcher应用程序一起使用,并且像在GWTquery教程中所说的那样在java文件内使用jQuery,那么在哪里安装jar文件以及如何导入它?

解决方案

GWTquery不使用jQuery,它是在GWT中实现的类似jQuery的 API并且它不需要jquery.js文件在GWT库或html主机页面中,您可以像其他gwt库一样轻松地添加它的jar文件:

Maven Setup



如果您想在现有的maven项目中添加GQuery,或者您不想使用maven原型,只需将以下行添加到你的pom.xml文件:

 <依赖关系> 
< dependency>
< groupId> com.googlecode.gwtquery< / groupId>
< artifactId> gwtquery< / artifactId>
< version> 1.1.0< / version>
<! - 如果您使用旧版本的gwt,请取消注释相应的行 - >
<! - < classifier> 2.1.0< / classifier> - >
<! - < classifier> 2.0.1< / classifier> - >
< scope>提供< / scope>
< /依赖关系>
< /依赖关系>

如果您不想使用maven,您可能有兴趣设置您的项目,或者它是一个已经创建的项目。
首先,您需要下载与您的GWT版本相关的最新稳定版本的gwtquery库,并将其放入您的类路径中。
如果您是一位经验丰富的GWT用户,您可能已经知道如何做到这一点,但如果您是初学者,请快速回顾一下。



首先,运行

  $ GWT_HOME / webAppCreator gwtquery.sample.Sample 

这将创建一堆包含示例项目的文件。找到build.xml文件并使用id =project.class.path添加

 < pathelement location = PATH_TO_DOWNLOADED_gwtquery-1.0-SNAPSHOT.jar/> 

如果您使用的是Eclipse,可能还需要编辑.classpath文件并添加以下内容:

 < classpathentry kind =libpath =PATH_TO_DOWNLOADED_gwtquery-1.0-SNAPSHOT.jar/> 

接下来,编辑src / gwtquery / sample / Sample.gwt.xml文件或您项目的现有模块文件,然后添加以下行来将GQuery导入GWT模块:

 < inherits name ='com.google.gwt .query.Query'/> 

最后,在你的模块入口点类(例如src / gwtquery / sample / client / Sample.java )添加以下导入语句以使GQuery易于使用:

  import com.google.gwt.query.client.GQuery; 
import com.google.gwt.query.client.Function;
import com.google.gwt.query.client.Selector;
import com.google.gwt.query.client.Selectors;
import static com.google.gwt.query.client.GQuery。*;
import static com.google.gwt.query.client.css.CSS。*;

更多信息


Can anyone tell me how to use GWTquery along with GWT? The GWTquery tutorial page mainly deals with how to use jQuery, it doesn't much explain how to embed it. If, for example, I want to use it with the default Stockwatcher app that comes with GWT, and use jQuery inside the java file just like the GWTquery tutorial says, where to install the jar file, and how to import it?

解决方案

GWTquery does not use jQuery, it is jQuery-like API implemented in GWT and it does not require jquery.js file inside GWT library or html host page, you can easily add its jar file like other gwt library:

Maven Setup

If you want to add GQuery on an existing maven project or you don't want to use the maven archetype, you have simply to add the following lines in your pom.xml file :

 <dependencies>
   <dependency>
     <groupId>com.googlecode.gwtquery</groupId>
     <artifactId>gwtquery</artifactId>
     <version>1.1.0</version>
     <!-- If you are using old versions of gwt, uncomment the appropriate line -->
     <!-- <classifier>2.1.0</classifier> -->
     <!-- <classifier>2.0.1</classifier> -->
     <scope>provided</scope>
   </dependency>
 </dependencies>

You could be interested in setting up your project by hand if you don't want to use maven, or it is an already created project. First you'll need to download the latest stable version of the gwtquery library related to your GWT version and place it in your classpath. If you're an experienced GWT user, you probably already know how to do this, but if you're a beginner, here's a quick refresher.

First, create a new project by running

$GWT_HOME/webAppCreator gwtquery.sample.Sample

which will create a bunch of files containing a sample project. Find the build.xml file and edit the section with id="project.class.path" adding

<pathelement location="PATH_TO_DOWNLOADED_gwtquery-1.0-SNAPSHOT.jar"/>

If you're using Eclipse, you may also want to edit the .classpath file and add the following:

<classpathentry kind="lib" path="PATH_TO_DOWNLOADED_gwtquery-1.0-SNAPSHOT.jar"/>

Next, edit the src/gwtquery/sample/Sample.gwt.xml file or your project's existing module file, and add the following line to import GQuery into your GWT module:

<inherits name='com.google.gwt.query.Query'/>

Finally, in your module entry point class (e.g. src/gwtquery/sample/client/Sample.java) add the following import statements to make GQuery easy to use:

import com.google.gwt.query.client.GQuery;
import com.google.gwt.query.client.Function;
import com.google.gwt.query.client.Selector;
import com.google.gwt.query.client.Selectors;
import static com.google.gwt.query.client.GQuery.*;
import static com.google.gwt.query.client.css.CSS.*;

More information.

这篇关于在GWT中使用GWTquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆