Nov 4, 2009

How to start working on GWT in Web Mode?

Eclipse Environment

Eclipse 3.4.2 with the following installed software:

Google App Engine Java SDK 1.2.1 (which I had to disable, as explained below)

Google Plugin for Eclipse 3.4

Google Web Toolkit SDK 1.6.4

Java Run Environment

JDK/JRE 1.6.0_14

Application Project

The GWT SDK contains a new "Web Application" project type and sample project for GWT application development.

GWT Libraries

GWT 1.7 , GXT 2.0, GWT-EXT 2.0.6 (using GXT because of lack of free RPC/MemStore library)

I placed the content of these under /Program Files (x86) in the appropriate following directories:

/GWT1.7

/GXT2.0

/GWTEXT2.0

Then in Eclipse, under Window->Preferences->Java->Build Path->User Libraries, I created three new libraries, GWT_1_7, GXT_2_0, GWTEXT_2_0 and added all the jars files from their corresponding directories.

Build Path

Right-click on the project and select Build Path. If the GWT SKD plugin is installed, the GWT libraries will already be there. Select Add Library=>User Library and add the libraries you need. I also added mysql-connector-jave-5.0.8-bin.jar, though I didn't check if it was necessary.

Get on the GWT mailing list to receive updates of GWT. When updating the GWT SDK, select Help=>Software Updates=>Google*. Install the update and restart. Then, as above, right-click on the project and select Build Path =>Add Library=>Google Web Toolkit and select the new SDK.

Run Configuration

Right-click on the project and select Run As->Run Configurations. The GWT SDK sets up most of this for you. I added -Xmx512M in the VM arguments window

Setting up servlet path

First, set up a servlet mapping in web.xml

war/WEB-INF/web.xml

In hosted mode, the moduleRelativeURL is http://localhost:8080/VinayWebApp/vin.

<servlet>

<servlet-name>VINServlet</servlet-name>

<servlet-class>edu.isi.page.vin.server.VinayServiceImpl</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>VINServlet</servlet-name>

<url-pattern>/VinayWebApp/vin</url-pattern>

</servlet-mapping>

Next, there are several places in the code where one must specify the mapping. I chose to use a shared constant so it would be easy to change. Formerly, the mapping was specified in WebApp.gwt.xml so this would not have covered all instances, but that is not necessary now.

VinayWebApp.gwt.xml

Old style (commented out): //<servlet path="/vin" class="edu.isi.page.vin.server.VinayServiceImpl"/>

client/VINConstants.java

public final static String VIN_SERVLET_PATH = "vin";

client/VinayWebApp.java

VINServiceAsync service = (VINServiceAsync) GWT.create(VINService.class);

ServiceDefTarget endpoint = (ServiceDefTarget)service;

String moduleRelativeURL = GWT.getModuleBaseURL() + VINConstants.VIN_SERVLET_PATH;

endpoint.setServiceEntryPoint(moduleRelativeURL);

client/VINService.java

New Style (replaced with): @RemoteServiceRelativePath(VINConstants.VIN_SERVLET_PATH );

For past servlets, for connection pooling, I have included a context.xml file with the following information, but it isn't necessary (at this point) for my GWT project so I don't know if the path for a <Context> tag would be /vin, /VinayWebApp, or /VinayWebApp/vin.

war/META-INF/context.xml

<Context path="/path">

<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver" name="jdbc..."

password="..." type="javax.sql.DataSource" url="jdbc:mysql..." username="..."/>

</Context>

Connecting to the mysql database

The line Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/ myschema", "myuser", "mypass"); was throwing a NoClassDefFound error, meaning that it couldn't access the mysql jar file. The com.mysql jar file was already in war/WEB-INF/lib, but having developed Tomcat servlets for years, I was used to dropping it into the Tomcat lib folder as well. So I tried placing it with other jars under eclipse/plugins/com.google.appengine.eclipse... and com.google.gwt.eclipse... without success. I finally happened on http://osdir.com/ml/GoogleWebToolkit/2009-06/msg01483.html and tried unchecking AppEngine. Sure enough it worked, and surprisingly, everything else continued to work, too.

Setting up for use with GXT

1. Download EXT 3.0

2. Place ext-all.js (etc.) as well as the entire adapter and resources folders under public/js/ext

3. Note: I had to place ext-all.js and ext-all-debug.js directly under public/ as well, even though all pointers in the <myapp>.gwt.xml files refer to these libraries by full path from js/ext/....

4. Note: All files in public/ get copied to war/<myapp>/ every time the hosted mode browser is refreshed.

Setting up for use with GWT EXT (must use EXT 2.0.2)

Getting started with GWT 2.0 (http://www.gwt-ext.com/wiki/index.php?title=Main_Page), especially the GWT 2.0 tutorial (http://gwt-ext.com/wiki/index.php?title=Tutorial:Introduction_to_GWT-Ext_2.0)

1. Download EXT 2.0.2

2. Place ext-all.js (etc.) as well as the entire adapter and resources folders under public/js/ext

3. Note: I had to place ext-all.js and ext-all-debug.js directly under public/ as well, even though all pointers in the <myapp>.gwt.xml files refer to these libraries by full path from js/ext/....

4. Note: All files in public/ get copied to war/<myapp>/ every time the hosted mode browser is refreshed.

When I include any GWT-EXT object in my GWT application I immediately get an Initializer Exception. The message out of javascript is "'$wnd.Ext' is null or not an object". Is there something more that I need to do. I have put:

<inherits name='com.gwtext.GwtExt'/>

in my module file; included the css and javascript file in the html; and put the javascript files in my public directory.

Testing under Tomcat:80

I started Tomcat using Services (I had previously set it to manual to avoid a potential port conflict with the hosted browser.) Pressed the Compile/Browse button on the hosted browser then moved the whole /war directory to Tomcat's webapp directory and renamed it /vin. http://localhost/vin did not work, but using the fully qualified name did, i.e. http://mymachine.mydomain.com/vin.

The war directory included:

\vin (\war renamed for placement under Tomcat\webapps)

\VinayWebApp

\gwt

\js

\resources

\WEB-INF

\classes

\lib

appengine-web.xml

logging.properties

web.xml

VinayWebApp.css

VinayWebApp.html

0 comments:

Text Widget

Copyright © Vinay's Blog | Powered by Blogger

Design by | Blogger Theme by