Thursday, 1 November 2012

building gwt project using maven

STEP 1 structure of gwt app

prayag@prayag:/backup/workspace.programming/workspace.gwt/eccount$ ls -l
total 172
-rw-rw-r-- 1 prayag prayag   1508 Sep 15 08:20 eccount-NO_SERVER.launch
-rw-rw-r-- 1 prayag prayag  15369 Aug 14 03:17 pom.xml
drwxrwxr-x 4 prayag prayag   4096 Jul 26 23:22 src
drwxrwxr-x 4 prayag prayag   4096 Nov  1 20:30 target


STEP 2 configuring GWT Maven Plugin developed by codehaus.org
“The Codehaus” is a collaborative environment for building opensource projects with a strong emphasis on modern languages.

Add maven-compiler-plugin configuration in the <plugins> node of the pom.xml file:


<project>
  [...]
  <build>
    <plugins>
      [...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>

      [...]

    </plugins>
  </build>
  [...]
</project>



add the maven-eclipse-plugin configuration in the <plugins> node of the pom.xml file:

<project>
  [...]
  <build>
    <plugins>
      [...]
    <!-- FACILITATES DOWNLOADING SOURCE AND JAVADOC IN ECLIPSE -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<wtpversion>2.0</wtpversion>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
      [...]
    </plugins>
  </build>
  [...]
</project>



STEP 3 configuring pom.xml to run the GWT compiler when the project is built

<project>
  [...]
  <build>
    <plugins>
      [...]

  <!-- GWT MAVEN PLUGIN -->

                          <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.4.0</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<force>false</force>
<gen>eccount/generated</gen>
</configuration>
</execution>
</executions>
<!-- Plugin configuration. There are many available options, see gwt-maven-plugin 
documentation at codehaus.org -->
<configuration>
<webappDirectory>${webappDirectory}</webappDirectory>
<force>true</force>
<gen></gen>
</configuration>
</plugin>

      [...]

    </plugins>
  </build>
  [...]
</project>


STEP 4 using maven-war-plugin

<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.zazzercode.eccount</groupId>
<artifactId>eccount</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>eccount</name>
<url>http://www.eccount.com</url>

  <build>

    <plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>exploded</goal>
<goal>war</goal>
</goals>
</execution>
</executions>
<configuration></configuration>
</plugin>

      [...]

    </plugins>
  </build>
  [...]
</project>


STEP 5 configuring maven-jetty-plugin
<project>
<build> 
 <plugins>
<!-- PLUGIN TO RUN AND TEST THROUGH MAVEN -->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.25</version>
<configuration>
<scanIntervalSeconds>3</scanIntervalSeconds>
</configuration>
</plugin>
    </plugins>
  </build>
  [...]
</project>

STEP 6 the final <build></build> node becomes as follows
<project>
  [...]
<pluginRepositories>
<pluginRepository>
<id>Codehaus Snapshots</id>
<url>http://repository.sourcesense.com/nexus/content/repositories/public</url>
</pluginRepository>
</pluginRepositories>

<build>
<finalName>eccount</finalName>
<plugins>

<!-- FACILITATES DOWNLOADING SOURCE AND JAVADOC IN ECLIPSE -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<wtpversion>2.0</wtpversion>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>

<!-- PLUGIN TO RUN AND TEST THROUGH MAVEN -->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.25</version>
<configuration>
<scanIntervalSeconds>3</scanIntervalSeconds>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>exploded</goal>
<goal>war</goal>
</goals>
</execution>
</executions>
<configuration></configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!-- GWT MAVEN PLUGIN -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.4.0</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<force>false</force>
<gen>eccount/generated</gen>
</configuration>
</execution>
</executions>
<!-- Plugin configuration. There are many available options, see gwt-maven-plugin 
documentation at codehaus.org -->
<configuration>
<webappDirectory>${webappDirectory}</webappDirectory>
<force>true</force>
<gen></gen>
</configuration>
</plugin>
</plugins>
</build>
  [...]
</project>

STEP 7 Install Dependencies
prayag@prayag:/backup/workspace.programming/workspace.gwt/eccount$ mvn clean install


STEP 8 eclipsify the project
prayag@prayag:/backup/workspace.programming/workspace.gwt/eccount$ mvn eclipse:eclipse

STEP 9 compile the project
prayag@prayag:/backup/workspace.programming/workspace.gwt/eccount$ mvn compile

Note
The above pom.xml is available at github/prayagupd/eccount-rest

References
The easiest way to create GWT-Maven project,  available at http://blog.widenhome.com/2011/01/29/the-easiest-way-to-create-gwt-maven-project/

GWT And Maven, available at http://www.artofsolving.com/node/53


No comments:

Post a Comment