Getting up and running with GWT and Netbeans

Get an install of GWT up and running

During my growing experience with GWT i learned that it is better to create the project from scratch and import it into the IDE rather then using a IDE-wizard which often creates not all files you need. So let’s start bei downloading the Google Web Toolkit Archive and extract it. Open a shell (Windows-User run “cmd“) and navigate to the directory where you have extracted the GWT-archive. Run the following commands:

  • webAppCreator.cmd -out MyProjectDirectory eu.jdevelop.gwt.MyApp
  • i18nCreator.cmd -eclipse MyGwtProject -createMessages -out MyProjectDirectory eu.jdevelop.gwt.client.constants.i18n.MyLanguageConstants

So what have you done? You have created a GWT-Project and added support for Eclipse and internationalization (i18n).

Create the ProjectCreate the Project


Change into the created directory MyProjectDirectory and run the following commands to see that all is working:

  • ant build
  • ant hosted
Running Ant targetsRunning Ant targets

Hosted ModeHosted Mode


Well done, now it is time to import this project into your favourite IDE.

Using NetBeans

Using NetBeans and GWT is not very difficult. Here i am using NetBeans v6.7.1 . First open in the menu “Tools“->”Plugins” and install the GWT4NB-Plugin.

Install the NetBeans PluginInstall the NetBeans Plugin


Create a new “Web Application“-Project:

Web ApplicationWeb Application


Choose a directory for it:

DirectoryDirectory


Select a Server:

ServerServer


Select the “Google Web Toolkit“-Framework in the next page and insert in the “GWT Module“-Textfield this: “eu.jdevelop.gwt.MyApp“. Notice the missing “client“-subpackage? It will be automatically created by the GWT4NB-Plugin.

GWT FrameworkGWT Framework


After that you will see the created project from the GWT4NB-Plugin:

GWT4NB ProjectGWT4NB Project


When you launch the application you can see that it is deployed into your previously selected Server:

Running in TomcatRunning in Tomcat

App in ChromeApp in Chrome


Where is now the “hosted mode” ? To use it, only click on the Debug-Button in the menu. To use Ant-Targets you have to make some changes. First open the “project properties” and change the “web page folder” from “web” to “war“:

Change the directoryChange the directory


Open the file “build.xml“, located inside your GWT-Project (created in Create the Project-files):

Original build.xmlOriginal build.xml


Copy the content inside the “<project></project>“-tags and insert it into the “build.xml“-file, located in your NetBeans-Project directory:

Changed build.xmlChanged build.xml


Replace all appearances of “src” with “src/java“, because source files are located in a different directory.

Search and replaceSearch and replace


You are now able to run the new ant targets “gwtc” and “hosted“:

new ant targetsnew ant targets


The last step is the integration of i18n. Copy the whole “…gwt-windows-1.7.1\MyProjectDirectory\src\eu\jdevelop\gwt\client\constants\“-directory into the corresponding directory of your NetBeans-project.

Copied contentCopied content


Don’t forget to copy the file “MyLanguageConstants-i18n.cmd“, you need it to create the i18n-java-file! You have to open it in NetBeans and update the source-directory (there are two!) to “src/java“:

Edit the i18n-fileEdit the i18n-file

Hosted mode in NetBeansHosted mode in NetBeans

Advertisements

About javatage

Java coder with a wandering eye (the grass always looks greener in the other guys API)
This entry was posted in Web Development. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s