Using GWTquery with GWT

落花浮王杯 提交于 2019-12-23 19:24:58

问题


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?


回答1:


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.




回答2:


You can find the complete step by step guide documented at the GWT Query Site - http://code.google.com/p/gwtquery/wiki/GettingStarted

Also you can find enough examples on internet apart from gwtquery-sample.



来源:https://stackoverflow.com/questions/14214441/using-gwtquery-with-gwt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!