Sunday, November 4, 2012

GWT Project Development Environment - 2. maven + eclipse + tomcat

This is a complete solution about how to set up a practical development environment with maven, eclipse and tomcat.
Before start you need to take some time to check if your system environment meet below system environmental requirements for windows if you use window.

Environmental requirements (Windows):

  • JDK
  • Ant (if you don't want to use ant command to run or build project not required)
  • Maven
  • gwt sdk
  • eclipse with plugins, m2e, maven integration forWTP, google plugin and sysdeo tomcat launcher.
  • Tomcat
  • Add directories of ant, maven and gwt sdk into path environment variable.

1. Create a gwt maven project

1.1 Approaches

There are two effective approaches to create a gwt maven project, by gwt maven plugin and gwt command line. I tried both approaches and chose the latter. Because the pom file generated by the latter is quite reasonable than the former. You don't need to make any change on pom.xml you can import it into eclipse directly without any error.
We need use gwt command line command webAppCreator. Before run this command you need to make sure you have added gwt sdk into your environment variable PATH.

1.2 webAppCreator

Use webAppCreater -help, you can get all the paramters which you can use.

WebAppCreator [-overwrite] [-ignore] [-templates template1,template2,...] [-out dir] [-junit pathToJUnitJar] [-maven] [-noant] moduleName

where
  -overwrite    Overwrite any existing files
  -ignore       Ignore any existing files; do not overwrite
  -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)
  -maven        Deprecated. Create a maven2 project structure and pom file (default disabled). Equivalent to specifying 'maven' in the list of templates.
  -noant        Deprecated. Do not create an ant configuration file. Equivalent to not specifying 'ant' in the list of templates.
and
  moduleName  The name of the module to create (e.g. com.example.myapp.MyApp)
-maven parameter is the key for generating gwt maven project.

1.3 Execute command 

Run
webAppCreator -maven com.martian.gwtmavenproject.MainPanel
com.gwtmavenproject.MainPanel is module name of this gwt project.

After execution you can get a standard maven project. There are only src folder, pom file and readme.txt under project root folder.
You may want to change the artifactId and groupId of this project.

2. Import into eclipse as maven project

Without any problem. Nothing can be accountable.

3. Use your own Tomcat in development mode instead of Jetty

3.1 Deploy project to your own Tomcat

Three methods, the latter two also can be applied to other types of application servers:
  • Use sysdeo Tomcat launcher plugin.
  • Use server tool of WTP. Just like a ordinary java web application, but don't forget to add the generated web sources to Deployment Assembly of the project if you want to run at product mode.
In fact, in this way you can use other sorts of web application server, such as some J2EE container.
  • Use an external Tomcat Server directly. If in this way you want to debug the server side code you   have to use remote debug.
The same principle of the two methods. The former may be more convenient when multiple applications share one tomcat server and you can start or stop in eclipse.
Now assume that you have successfully deployed gwt project to your Tomcat server.

3.2 Launch project in development mode

The principle will be used latter references Compile & Debug of gwt application.

a. Right click project in project explorer --> Debug As --> Web Application (running on an external server)



b. Specify external server URL and launch development mode

    You can access your application with http://localhost:8080/gwtmavenproject/. So
Click ok to development mode.

c. Start your Tomcat

If you use sysdeo up Tomcat
you have to change the output console manually in eclipse for seeing them.

d. Enjoy your development time!

It is powerful in that we can debug client-side code.

e. Edit debug configuration

If you still have something to change you can access
Find the configuration just created.
You can change some start arguments like -logLevel, change it from INFO to DEBUG.

No comments:

Post a Comment