| Summary: How to setup GWT, GXT and Maven |
| Author: DroidIn.net |
| Published: 08/04/2009 |
| Ext Version: 2.0.1 |
Languages: English
|
Contents |
This tutorial covers step-by-step creation of a simple GXT/GWT/Maven project utilizing the following tools:
It's intended for developers and anyone who wants to become familiar with GWT and the toolstack
mvn \-versionand get the result. Don't have Maven yet? Time to visit Maven site [6]
mvn archetype:generate \ -DarchetypeRepository=http://snapshots.repository.codehaus.org \ -DarchetypeGroupId=org.codehaus.mojo -DarchetypeArtifactId=gwt-maven-plugin \ -DarchetypeVersion=1.1 -DgroupId=com.mycompany.foo -DartifactId=gwtest
<repositories> <repository> <id>codehaus-maven-repo</id> <name>Codehaus repo</name> <url>http://repository.codehaus.org/org/codehaus/mojo/</url> </repository> </repositories>
<gwt.version>1.7.0</gwt.version>
mvn verifywhich will pull in various dependency JARs and run tests
<configuration> <runTarget>com.mycompany.foo.Application/Application.html</runTarget> </configuration>
This target, of course can be changed later if you rename any packages or file names
mvn gwt:runthat should bring up your app in the hosted mode
Adding extGWT is as easy as adding another dependency. Let's make it a little better configurable following GWT conventions. So in your pom.xml:
<gxt.version>2.0.1</gxt.version>
<dependency> <groupId>com.extjs</groupId> <artifactId>gxt</artifactId> <version>${gxt.version}</version> <scope>provided</scope> </dependency>
It was fun but we want to develop our project in Eclipse. Here are the steps (order is important)
Eclipse->File->Import->General->"Maven project"and navigating to the folder that contains your project
mvn gwt:eclipsefrom command line
From now on tutorial will refer to root of your project (as seen in Eclipse) as $PROJECT
As is - our only test file generates some errors in Android console. To get rid of these add the following line into Application.gwt.xml
<source path="client" excludes="*/*Test*.java" />
WARNING: Do not name your "regular" java file TestSomething.java that is reserved for "real" test classes!!!
We don't have to worry about gxt.jar however we still need bring in non-java files and add some configurations. So you will need to download actual extGWT distro. Once you have it:
<script language='javascript' src='resources/flash/swfobject.js'></script> <link rel="stylesheet" type="text/css" href="resources/css/gxt-all.css" />
<inherits name='com.extjs.gxt.ui.GXT'/>
<inherits name='com.google.gwt.user.theme.standard.Standard'/>
package com.mycompany.foo.client; import com.extjs.gxt.ui.client.event.ButtonEvent; import com.extjs.gxt.ui.client.event.SelectionListener; import com.extjs.gxt.ui.client.widget.LayoutContainer; import com.extjs.gxt.ui.client.widget.TabItem; import com.extjs.gxt.ui.client.widget.TabPanel; import com.extjs.gxt.ui.client.widget.Window; import com.extjs.gxt.ui.client.widget.button.Button; import com.extjs.gxt.ui.client.widget.layout.FitData; import com.extjs.gxt.ui.client.widget.layout.FitLayout; import com.extjs.gxt.ui.client.widget.layout.FlowLayout; public class HelloWorldExample extends LayoutContainer { public HelloWorldExample() { setLayout(new FlowLayout(10)); final Window window = new Window(); window.setSize(500, 300); window.setPlain(true); window.setModal(true); window.setBlinkModal(true); window.setHeading("Hello Window"); window.setLayout(new FitLayout()); TabPanel panel = new TabPanel(); panel.setBorders(false); TabItem item1 = new TabItem("Hello World 1"); item1.addText("Hello..."); item1.addStyleName("pad-text"); TabItem item2 = new TabItem("Hello World 2"); item2.addText("... World!"); item2.addStyleName("pad-text"); panel.add(item1); panel.add(item2); window.add(panel, new FitData(4)); window.addButton(new Button("Hello")); window.addButton(new Button("World")); Button btn = new Button("Hello World"); btn.addSelectionListener(new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { window.show(); } }); add(btn); } }
/** * This is the entry point method. */ public void onModuleLoad() { HelloWorldExample hello = new HelloWorldExample(); RootPanel.get().add( hello ); }
mvn gwt:run. You should see a window with a single button "Hello". Go ahead - click on it!