Tuesday, August 23, 2011

Create Maven GWT project and setup eclipse project

Using Maven archetype you can very easily create the gwt project in Maven. Follow below steps to create the same.

Assumption: You have latest version of maven installed (Tried the below steps with 3.0.3 version)
  1. mvn archetype:generate
  2. It will ask for archetype to use specify 258 (gwt-maven-plugin).
  3. Then it will ask for other details like any other archetype asks for, enter the required details. And it will create the given GWT project with the details you have entered with a sample application.
  4. Once the project is created open pom.xml and change gwt-servlet and gwt-user dependencies version to the version you want.
  5. try building the project and test the sample project.
 Above steps will create the GWT project with sample application.

  Following are the steps to import this Maven project inside Eclipse and setup eclipse WebProject for the same.
  • Install GWT eclipse plugin (http://dl.google.com/eclipse/plugin/3.6) for more details refer (http://code.google.com/webtoolkit/usingeclipse.html).
  • Install required maven plugins refer (http://pandurang-patil.blogspot.com/2011/08/setup-eclipse-project-from-maven.html) just refer "Install maven eclipse plug-in" section.
  •  Once you are done with installing all the required plugins. Click on "Window=>Preferences". Eclipse Preferences window will appear.

  • Select "Maven" on the left hand side. You will see "Goals to run on import project" enter "process-resources" in that field same as that of immediate below field. And click on "OK".
  • Once you are done with those changes import the Maven project into eclipse as per steps referred under section "To setup eclipse project for your maven project follow below steps" of Setup eclipse project from a Maven project. It might take some time to download some dependencies.
  • Once you are done with importing the project inside eclipse. To run and debug imported GWT application inside eclipse you need to follow few more steps.
  • Right click on imported project and select "Properties".

  •  On Properties window expand "Google" and select "Web Toolkit" and check "Use Google Web Toolkit" check box and select the GWT sdk version.

  • Select "Java Build Path" and then select "Source" tab from right hand side panel. You need to remove excluded ** for <project>/src/main/resource and <project>/src/test/resource as "<module>.gwt.xml" files are created inside resource folder as per maven standard and while importing it in to Eclipse, it excludes the contents of resource folder for some reason.
  • Now you are all set to run the application
  • Right click on project and select "Run as"=>"Web Application" it will run the application with embedded tomcat.

  • You will see application running on "Development Mode" panel right click on url select "Open With" and add browser. 

  • Select the browser executable with path. And it will open the application on given browser in dev mode.
  • If you are running the GWT application first time on given browser it will ask you to install GWT Plugin. Install that plugin and hit the url once again.
  • You will see above sample application opened in your selected browser.


Thursday, August 11, 2011

Setup eclipse project from a Maven project

Note: Below steps will work for 2.x and later version's of Maven project.

Assumption: You know eclipse. 

Eclipse version details:  I would recommend to use latest version of Eclipse (Helios was the latest version while writing this blog and steps are tried with the same).

If you know how to install eclipse plugin then you can skip install steps and install following two plugins 
  1.  http://m2eclipse.sonatype.org/sites/m2e
  2.  http://m2eclipse.sonatype.org/sites/m2e-extras
Install maven eclipse plug-in (refer http://m2eclipse.sonatype.org/installing-m2eclipse.html). 
Follow below steps to install eclipse plug-in.
    • Click on “Help”=>”Install New Software”

    • Click on “Add” button on “Install” window.

    • On “Add Repository” window add any meaning full name like in this case “maven” and the corresponding URL for eclipse plugin (http://m2eclipse.sonatype.org/sites/m2e). And click on “Ok” button.

    • check all required and click on “Next” follow the wizard and finally finish. It will install the plugin.
    • similarly install m2eclipse Extras URL (http://m2eclipse.sonatype.org/sites/m2e-extras).
 Once you install both the eclipse plug-ins for Maven your eclipse is ready to import Maven project. When you install those plug-in's it also installs Embedded Maven and it uses the same for imported projects. If you want to use other version of maven which installed on your machine. You can do the same follow below steps to select installed version of Maven.
    • Click on Window=> Preferences

    • On Preferences window expand “Maven” and select “Installations”.
    • Under “Installations” option click on “Add” to select maven installation installed in previous steps. 
    • When you click on add, it will pop up a folder browser window. Select the home location of maven installation in that Window.

    • Once you select the maven installation home folder click on “Apply” and then click on “OK”.
To setup eclipse project for your maven project follow below steps.



    • Click on menu File=>Import...

    • On "Import" Window expand "Maven" tag and select "Existing Maven Projects". And click on "Next" button.

    • On "Import Maven Projects" window click on Browse and select your base project folder which contains pom.xml. If you have multiple projects with one parent project. Just select the folder of parent project.

    • Once you select the base folder it will show you the project/projects. Click on "Finish" button. It will setup the required project/projects for you.

    • It creates required project as per packaging type. If packaging type is "war" it will create eclipse web project. It will add corresponding resources into source path, add web resource and also add dependencies inside classpath.