Command Line Tools
The GWT includes a set of tools that can be run from the command-line to simplify and speed up common tasks.
Configuring your PATH
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.
Windows
- Right-click on My Computer and select Properties
- Open the Advanced tab.
- Click the Environment Variables button.
- From the user variables list, select Path and click Edit
- At the end of the of the variable value, add a semicolon followed by the full path to the directory where you unpacked the GWT distribution (e.g.,
;C:\gwt-2.0.0\
).
Mac or Linux
Edit a file named .profile
or .bash_profile
in your home directory.
For example, if you unpacked GWT in /home/user/gwt-2.0.0/
, update your profile as follows:
PATH=$PATH:/home/user/gwt-2.0.0/
export PATH
You will need to log out of your account and log back in before the PATH setting takes effect.
webAppCreator
A command-line tool that generates a starter application and scripts for launching development mode and compiling to JavaScript. Use the files generated by these scripts as a starting point for building your own project.
webAppCreator [-[no]overwriteFiles] [-[no]ignoreExistingFiles] \
[-templates template1,template2,...] [-out dir] \
[-junit pathToJUnitJar] [-[no]maven] [-[no]ant] moduleName
Parameter | Definition |
---|---|
-[no]overwriteFiles | Overwrite any existing files. (defaults to OFF) |
-[no]ignoreExistingFiles | Ignore any existing files; do not overwrite. (defaults to OFF) |
-templates | Specifies the template(s) to use (comma separeted). Defaults to 'sample,ant,eclipse,readme' |
-out | The directory to write output files into (defaults to current) |
-junit | Specifies the path to your junit.jar (optional) |
-[no]maven | DEPRECATED: Create a maven2 project structure and pom file (default disabled). Equivalent to specifying 'maven' in the list of templates. (defaults to OFF) |
-[no]ant | DEPRECATED: Create an ant configuration file. Equivalent to specifying 'ant' in the list of templates. (defaults to OFF) |
moduleName | The name of the module to create (e.g. com.example.myapp.MyApp) |
Examples
You can select either ant
or maven
build system. Based on your selection you will get a different build script, and a different folder structure.
Since nowadays Maven is widely used and importing maven projects in IDE is easier, it's better that you select it for your new GWT projects.
Creating a Maven
project.
webAppCreator -out foo -templates maven,sample,readme com.example.foo.Foo
The generated files are used as follows:
- Running
mvn gwt:run
from the command-line brings up the new application in superDevMode. - Running
mvn package
from the command-line translates the Java app to JavaScript, creating awar
file into the target directory. - The other files in src implement a small sample GWT application, with the appropriate
web.xml
file and tests.
Note: because of a bug in GWT-2.7.0, it generates a broken pom.xml
, hence, you have to modify the <dependencyManagement>
block to include the <type>
parameter:
<dependencyManagement>
<dependencies>
<!-- ensure all GWT deps use the same version (unless overridden) -->
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt</artifactId>
<version>${gwtVersion}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
Creating an Ant
project.
webAppCreator -junit /path/to/junit-3.8.1.jar -out foo com.example.foo.Foo
The generated files are used as follows:
- Running
ant devmode
from the command-line brings up the new application in superDevMode. - Running
ant build
from the command-line translates the Java app to JavaScript, creating a web folder calledfoo
in thewar
directory. Foo.launch
is a launch configuration for Eclipse.FooTest-dev.launch
is a launch configuration for Eclipse that will run the project's tests in development mode.FooTest-prod.launch
is a launch configuration for Eclipse that will run the project's tests in production mode.- The other files implement a small sample GWT application.
You will notice that the build.xml
file contains a number of rules to compile and deploy your application. These will help to resolve the libraries needed at compile-time and runtime to compile and deploy your application, respectively.
Notice also that there are some properties 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).
i18nCreator
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] [-[no]overwriteFiles] \
[-[no]createConstantsWithLookup] [-[no]createMessages] \
[-[no]ignoreExistingFiles] interfaceName
Parameter | Definition |
---|---|
-eclipse | Creates a i18n update launch config for the named eclipse project. |
-out | The directory to write output files into (defaults to current) |
-[no]overwriteFiles | Overwrite any existing files. (defaults to OFF) |
-[no]createConstantsWithLookup | Create scripts for a ConstantsWithLookup interface rather than a |
-[no]createMessages | Create scripts for a Messages interface rather than a Constants one. (defaults to OFF) |
-[no]ignoreExistingFiles | Ignore any existing files; do not overwrite. (defaults to OFF) |
interfaceName | The fully qualified name of the interface to create |
Example
~/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.