First I must admit that I don't buy GWT's approach. There is a reason why we don't write HTML code from servlets anymore. Programmers usually are bad UI designers (look at my website for something to back my claim ;-) and great UI designers usually don't want to write Java code. With the GWT model you write your UI in Java and automatically translate it to HTML. This means layout changes require the Java coder to perform it, which is bad. Maybe you can get around most problems with the help of CSS, but I doubt that.
Anyway, I downloaded the toolkit and played with it last night, and found it to be a bit cumbersome to work with. Scripts that generate scripts and no integration with Ant to speak of.
I stopped after my first few steps and started to put together a little Ant library that makes using GWT a bit less cumbersome - at least to me. This is very rough alpha level code, but it works for me. I'm not sure I'll take this any further, but if anybody is interested in it, feel free to use the code - the license is pretty permissive. Source and binaries are available here.
There is no documentation right now. A quick rundown:
- This is an Ant library which means you need Ant 1.6.0 or better. It lives in the antlib:de.samaflost.gwttasks namespace by default.
- Throughout the rest of this blog entry I'll assume you have something like xmlns:gwt="antlib:de.samaflost.gwttasks" on your <project> tag.
- All tasks have a mandatory
gwtHome
attribute that points to your GWT installation. - gwt:projectCreator is almost as pointless as the corresponding script. The major difference is that it doesn't create any Eclipse stuff and that the generated Ant build file is a tiny bit cleaner. Don't use this task. 8-)
- gwt:applicationCreator is similar to the corresponding
script but creates an Ant build file which includes the compile,
clean and package targets projectCreator would have created but also
contains a bunch of additional targets leveraging the other
tasks.
This task has an optional
dir
attribute pointing to the directory that you want to hold your GWT project structure and a mandatoryclassName
attribute (corresponding to the className argument the applicationCreator script of GWT requires).There also is an optional boolean attribute that controls the
-eclipse
command line argument of the applicationCreator script that is called under the covers.The
outDir
is only used while writing the build file, it provides the value for the next two tasks'outDir
attributes and defaults to "www"./p>Finally there is a
template
attribute that can be used to point to a build file template if you don't like the one created by this task. The token@PROJECT@
will be replaced by the last part of the className attribute,@GWT_HOME@
will point to gwtHome,@CLASS_BASE@
is className without ".client" and@OUT@
is the outDir attribute. - gwt:compile runs the Java -> JavaScript compiler.
The
outDir
andclassBase
attributes make up the output directory - in the script generated by the applicationCreator script they are "www" and className without ".client" repectively.There is an optional
dir
attribute if your GWT application's src directory is not directly below your basedir. - gwt:shell starts the GWT shell and takes the same
arguments as the compile task - only
classBase
is replaced bystartPage
which is built by appending the unqualified class name to what would be compile'sclassBase
plus a slash and adding an ".html" extension.
Reading this a second time, it is a bit confusing, I guess.
You must provide a class name to Google's applicationCreator
script, let's say you've chosen de.samaflost.client.Dummy
(the .client. piece is recommended by Google), then
gwt:compile
's classBase
would be
de.samaflost.Dummy
and startPage
would be
de.samaflost.Dummy/Dummy.html
.
Putting the stuff together. To seed a new GWT application you'd use
<target name="applicationCreate"> <mkdir dir="project"/> <gwt:applicationCreator dir="project" gwtHome="C:/OSS/gwt-windows-1.0.20/" className="de.samaflost.client.Dummy"/> </target>
This will generate the initial directory structure in the
project
subdirectory and will also generate an Ant build
file that contains (among other things)
<target name="gwt-compile" depends="compile"> <gwt:compile outDir="www" gwtHome="C:\OSS\gwt-windows-1.0.20" classBase="de.samaflost.Dummy"/> </target> <target name="gwt-shell" depends="compile"> <gwt:shell outDir="www" gwtHome="C:\OSS\gwt-windows-1.0.20" startPage="de.samaflost.Dummy/Dummy.html"/> </target>
This means you don't need to worry about classBase or startPage at all. It also means you now have the Java -> JavaScript step as part of your Ant build process and available to your continuous integration runs.
I haven't found the time for an actual RPC example yet, but expect
it will lead me to a special gwt:war
task that knows what
to package where.
Finally, it may be worth noting that three of the four tasks are
implemented in Ant, not Java (i.e. they are
<macrodef>
's hidden in the antlib descriptor.
path: /en/Java/GWT | #
defmacro.org has a tutorial with the subject The Nature of Lisp that introduces some concepts of Lisp by building on the more widely known concepts of XML and Ant's usage of it. via John Lam
I really enjoyed reading the tutorial, it takes a different approach that may be more accessible than many others. Since I've been into Lisp (the Emacs dialect, mostly) before, I can't say whether the tutorial can convince a developer to learn Lisp - go and read it to find out.
The story of Ant's inception is a year late, I guess. Given James' take on Ant using XML today[1] he'd probably disagree with the assertion that using XML was one of the reasons for Ant's success. I think it's a question of having an extensible syntax, not of the syntax itself - which makes me happily agree with the tutorial.
One nit:
In Almost
Lisp the author introduces what would be the <macrodef>
task with "If Ant supported ...". I'd probably rewrite the section
with
<macrodef name="Test"> <sequential> <echo message="Hello World!"/> </sequential> </macrodef>and in fact I've suggested just that via email.
[1] I can't find it online anymore, this seems to be the best alternative