Google Code offered in: English - Español - 日本語 - 한국어 - Português - Pусский - 中文(简体) - 中文(繁體)
The Google Web Toolkit includes a set of tools that can be run from the command-line to simplify and speed up common tasks.
To easily invoke the command-line tools without entering their full path names, add them to your system command search path. To do this, in the PATH environment variable, identify the directory in which you unpacked the GWT distribution.
;C:\gwt-windows-1.6.4\).
Edit a file named .profile or .bash_profile in your home directory.
For example, if you unpacked GWT in /home/user/gwt-linux-1.6.4/, update your profile as follows:
PATH=$PATH:/home/user/gwt-linux-1.6.4/ export PATH
You will need to log out of your account and log back in before the PATH setting takes effect.
A command-line tool that generates a starter application and scripts for launching hosted mode and compiling to JavaScript. Use the files generated by these scripts as a starting point for building your own project.
webAppCreator [-overwrite] [-ignore] [-out dir] [-XnoEclipse | -XonlyEclipse] moduleName
-out-overwrite-ignoremoduleName~/Foo> ./webAppCreator -out foo com.example.foo.Foo Created directory foo/src Created directory foo/war Created directory foo/war/WEB-INF Created directory foo/src/com/example/foo Created directory foo/src/com/example/foo/client Created directory foo/src/com/example/foo/server Created file foo/src/com/example/foo/Foo.gwt.xml Created file foo/war/Foo.html Created file foo/war/Foo.css Created file foo/war/WEB-INF/web.xml Created file foo/src/com/example/foo/client/Foo.java Created file foo/src/com/example/foo/client/EchoService.java Created file foo/src/com/example/foo/client/EchoServiceAsync.java Created file foo/src/com/example/foo/server/EchoServiceImpl.java Created file foo/build.xml Created file foo/.project Created file foo/.classpath Created file foo/Foo.launch
The generated files are used as follows:
ant hosted from the command-line brings up the new application in hosted mode.ant build from the command-line translates the Java app to JavaScript, creating a web folder called foo in the war directory.Foo.launch is a launch configuration for Eclipse.You will notice that the build.xml file contains a number of rules to compile and deploy your application. These will help resolve the libraries needed at compile time / run time to compile and deploy your application, respectively. The generated build.xml file for the Foo project above will look like the following:
<?xml version="1.0" encoding="utf-8" ?>
<project name="Foo" default="build" basedir=".">
<!-- Configure path to GWT SDK -->
<property name="gwt.sdk" location="C:/gwt-windows-1.6.4" />
<path id="project.class.path">
<pathelement location="war/WEB-INF/classes"/>
<pathelement location="${gwt.sdk}/gwt-user.jar"/>
<fileset dir="${gwt.sdk}" includes="gwt-dev*.jar"/>
<!-- Add any additional non-server libs (such as JUnit) -->
<fileset dir="war/WEB-INF/lib" includes="**/*.jar"/>
</path>
<target name="libs" description="Copy libs to WEB-INF/lib">
<mkdir dir="war/WEB-INF/lib" />
<copy todir="war/WEB-INF/lib" file="${gwt.sdk}/gwt-servlet.jar" />
<!-- Add any additional server libs that need to be copied -->
</target>
<target name="javac" depends="libs" description="Compile java source">
<mkdir dir="war/WEB-INF/classes"/>
<javac srcdir="src" includes="**" encoding="utf-8"
destdir="war/WEB-INF/classes"
source="1.5" target="1.5" nowarn="true"
debug="true" debuglevel="lines,vars,source">
<classpath refid="project.class.path"/>
</javac>
<copy todir="war/WEB-INF/classes">
<fileset dir="src" excludes="**/*.java"/>
</copy>
</target>
<target name="gwtc" depends="javac" description="GWT compile to JavaScript">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<pathelement location="src"/>
<path refid="project.class.path"/>
</classpath>
<!-- add jvmarg -Xss16M or similar if you see a StackOverflowError -->
<jvmarg value="-Xmx256M"/>
<!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
<arg value="com.example.foo.Foo"/>
</java>
</target>
<target name="hosted" depends="javac" description="Run hosted mode">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.HostedMode">
<classpath>
<pathelement location="src"/>
<path refid="project.class.path"/>
</classpath>
<jvmarg value="-Xmx256M"/>
<arg value="-startupUrl"/>
<arg value="Foo.html"/>
<!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
<arg value="com.example.foo.Foo"/>
</java>
</target>
<target name="build" depends="gwtc" description="Build this project" />
<target name="war" depends="build" description="Create a war file">
<zip destfile="Foo.war" basedir="war"/>
</target>
<target name="clean" description="Cleans this project">
<delete dir="war/WEB-INF/classes" failonerror="false" />
Notice that there are some properties here that you might like to extract to a build.properties file, such as the gwt.sdk property, to make it easier to share the same build script with teammates who may have different configurations on their development machines. Also, this build.xml file serves as an excellent base to grow on as your project takes on more dependencies or requires more specific build targets (for example, unit testing targets).
A command-line tool that generates scripts to help with static string internationalization, along with sample properties files. Modify the .properties files to suit your project. Run the generated
<classname>-i18n script to (re)generate a Java interface for accessing the tags defined in your properties files.
i18nCreator [-eclipse projectName] [-out dir] [-overwrite] [-ignore]
[-createMessages] [-createConstantsWithLookup] interfaceName
-eclipse -out-overwrite-ignore-createMessages-createConstantsWithLookupinterfaceName~/Foo> i18nCreator -eclipse Foo -createMessages com.example.foo.client.FooMessages Created file src/com/example/foo/client/FooMessages.properties Created file FooMessages-i18n.launch Created file FooMessages-i18n
Running FooMessages-i18n will generate an interface class in a file named FooMessages.java from FooMessages.properties that extends Messages
(The messages will take parameters, substituting {n} with the nth parameter).
~/Foo> i18nCreator -eclipse Foo com.example.foo.client.FooConstants Created file src/com/example/foo/client/FooConstants.properties Created file FooConstants-i18n.launch Created file FooConstants-i18n
Running FooConstants-i18n will generate an interface from FooConstants.properties that extends Constants (The constants will not take parameters). To
create a ConstantsWithLookup class, pass the -createConstantsWithLookup option.
In both examples, The launch configurations do the same thing as the scripts, but are intended to be run from within the Eclipse IDE.
Tip: When new entries are added to the properties file, the -i18n scripts must be run again.
A command-line tool that generates a JUnit test and scripts for testing in both hosted mode and web mode. Use these scripts as a starting point for building your own JUnit test suites based on GWTTestCase or Benchmark subclass.
junitCreator -junit pathToJUnitJar [-eclipse projectName] [-out dir]
[-overwrite] [-ignore] [-addToClassPath] className
-junit-module-eclipse-out-overwrite-ignore-addToClassPathclassName
The following is an example of creating a test class that implements GWTTestCase.
The example assumes that you have already created a module named com.example.foo.Foo:
~/Foo> junitCreator -junit /opt/eclipse/plugins/org.junit_3.8.1/junit.jar
-module com.example.foo.Foo
-eclipse Foo com.example.foo.client.FooTest
Created directory test/com/example/foo/test
Created file test/com/example/foo/client/FooTest.java
Created file FooTest-hosted.launch
Created file FooTest-web.launch
Created file FooTest-hosted
Created file FooTest-web
After creating the skeleton and launch file, add your testing logic to the generated class file FooTest.java.
Make sure to compile the class using javac or your IDE.
Running FooTest-hosted tests the methods in test/com/example/foo/client/FooTest.java as Java bytecode in a JVM.
FooTest-web tests as compiled JavaScript.
The launch configurations do the same thing in Eclipse.
Reads benchmark reports from a folder and displays their results, including various visualizations.
benchmarkViewer [path]
path~/Foo> benchmarkViewer my/benchmark/results
Looks for report XML files in the folder my/benchmark/results and displays them in the viewer.