Google Web Toolkit
by Bruce Perry
|
Pages: 1, 2, 3, 4, 5
Build File
Below are the highlights of the Ant build file; it:
- Compiles the Java files into the project directory's ./classes directory.
- Executes the GWT compile script (in this case called
MyForm-compile). - Moves the resulting code generated in the ./www directory to a larger web application already deployed on Tomcat.
- Copies the compiled Java servlet and associated interface (ShowRespService) to that same web application.
The two Ant targets that compile the Java classes and initiate the conversion to JavaScript are designed to make the overall build fail if these tasks raise any errors.
Ant XML
Here's what the gwtpoj.properties file contains, among other values:
web.deploy.location=/users/bruceperry/parkerriver/gwt web.classes.location=/users/bruceperry/parkerriver/WEB-INF/classes
The following XML represents just the highlights from the Ant file; the entire file is linked in the resources section of this article.
<?xml version="1.0" encoding="UTF-8"?>
<project name="gwtproj" default="all">
<property file="gwtproj.properties"/>
<!-- The top-level directory for the project and
where the ant file resides -->
<dirname property="module.gwtproj.basedir" file="${ant.file}"/>
<!-- The ./classes directory inside the top-level directory -->
<property name="gwtproj.output.dir" value=
"${module.gwtproj.basedir}/classes"/>
<!-- This target calls MyForm-compile to create
all the content in the ./www directory -->
<target name="gwt-compile" depends=
"compile.production.classes"
description="use gwt's compiler">
<delete>
<fileset dir="${web.deploy.location}" includes="**/*"/>
</delete>
<exec executable=
"${module.gwtproj.basedir}/MyForm-compile"
failonerror="true"/>
<copy todir="${web.deploy.location}">
<fileset dir=
"${module.gwtproj.basedir}/www">
</fileset>
</copy>
</target>
<target name="compile.production.classes" description=
"Compile the gwtproj production classes">
<mkdir dir="${gwtproj.output.dir}"/>
<javac destdir="${gwtproj.output.dir}" debug=
"on" failonerror="true" nowarn=
"off" memoryMaximumSize="128m" fork=
"true" executable="${module.jdk.home.gwtproj}/bin/javac">
<classpath refid="gwtproj.module.classpath"/>
<src refid="gwtproj.module.sourcepath"/>
</javac>
</target>
<!-- copy the Java servlet classes to the web application -->
<target name="deploy.classes" depends="gwt-compile"
description="copy classes to web directory">
<copy todir="${web.classes.location}">
<fileset dir="${gwtproj.output.dir}">
</fileset>
</copy>
</target>
<target name="all" depends="deploy.classes"
description="build all"/>
</project>
You can run this Ant file from within the IDE (as in IntelliJ) or by using this command line in the directory that contains the build file:
ant -buildfile gwtproj.xml
For the most part, after making application changes and running Ant, you can see the changes in the browser by reloading the browser page.
Final Set-Up
The last set-up aspect you may have to know about is adding the gwt-user.jar library to the /WEB-INF/lib directory of your web application.
I created my own JAR file minus the javax package, named it gwt-user-deploy.jar, and added it to /WEB-INF/lib. This is because Tomcat will not load an individual web application's library if it contains the servlet API classes.