I promised I would put up another post on the new job, but unfortunately I have been so swamped at the new gig that I haven’t had the time to post anything.
Here is the run down. I am working for a consulting firm in the Atlanta area doing J2EE development for a major hotel chain. Technology wise, the project involves, GWT for the presentation layer, Spring(MVC and IOC) for the J2EE framework as well as the transaction management and hibernate for the data persistence layer. We are using Agile for our project methodology, Eclipse Galileo for our IDE, and Oracle for our database.
As with most projects there were a few initial hurdles to get over.. such as making Maven and GWT 2.0 work nicely together, and being able to deploy to Artifactory. We also had issues with getting the Embedded Jetty server (comes with the GWT plugin) running with JNDI. We could never get this to work, so we just decided to use straight JDBC locally for the embedded server and deploy the app using JNDI to Artifactory for deployment to the other environments.
After getting a breather(some call this the weekend!) and refocusing on GWT and Maven without a deadline looming, I found this article on how to configure GWT 2.0 and the Maven Plugin within eclipse.
If this link works for you, let me know.. but for me I had many issues.
First of all, I typically run maven from the command line and not from within the Eclipse IDE.. maybe that’s not the ideal way to do things, but I feel it better models the current examples on the web which are IDE agnostic.
1.) Regarding the post, just changing gwt.version from 1.7.1 to 2.0 didn’t force Maven to do a refresh of the newer GWT modules. I had to actually edit the version for the GWT plugins to cause a refresh to occur. If there is a better way let me know and I will edit this post.
2.) I kept receiving an error referring to the GWTTestSimple class mentioning that this needed to be recompiled. After some trial and error I realized I couldn’t just do a mvn clean to clean what was in my war/WEB-INF/lib directory. The 1.7.1 versions keep staying around. So I physically deleted them.
3.) I had to add the following to my web.xml (why are my test cases being copied into the war?)
<servlet>
<servlet-name>jUnitHostImpl</servlet-name>
<servlet-class>com.google.gwt.junit.server.JUnitHostImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>jUnitHostImpl</servlet-name>
<url-pattern>/com.theartoftech.gwt20example.Application/junithost</url-pattern>
</servlet-mapping>
4.) mvn clean will clean everything in the target directory(and delete this directory), but not in the war directory – as referenced in 2 – which is from where gwt:run will run the embedded server. You must either add an ant task to your pom.xml or delete it by hand.
5.) mvn gwt:compile will compile your gwt code into javascript and place this in your target directory. (Directory named target/[war snapshot name])
6.) mvn install will run your test cases, and move your WEB-INF and META-INF into the target directory under your [war snapshot name] directory. This doesn’t however move anything into your war directory.
7.) mvn gwt:run will copy your client side javascript + htm/css to your war directory as well as your WEB-INF (including lib and classes). Curiously there will be no web.xml file copied.
I received errors like this; Module declares 1 <servlet> declaration(s), but a valid ‘web.xml’ was not found at c:\some\path\to\my\war\WEB-INF\web.xml
8.) Enter Ant – probably not the best way to do this, but I have never figured out an easy way to copy files within maven that works better than this. After making this change the web.xml gets copied to war/WEB-INF
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<mkdir dir=”./war/WEB-INF” />
<copy overwrite=”true” todir=”./war/WEB-INF/”>
<fileset dir=”./src/main/webapp/WEB-INF”>
<include name=”web.xml” />
</fileset>
</copy>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
My Pom.xml:
<?xml version=”1.0″ encoding=”UTF-8″?>
<project xmlns=”http://maven.apache.org/POM/4.0.0″ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd”>
<!–
POM generated by gwt-maven-plugin archetype
–>
<modelVersion>4.0.0</modelVersion>
<groupId>com.theartoftech</groupId>
<artifactId>gwt20example</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<properties>
<!– convenience to define GWT version in one place –>
<gwt.version>2.0.0</gwt.version>
<!– tell the compiler we can use 1.5 –>
<maven.compiler.source>1.5</maven.compiler.source>
<maven.compiler.target>1.5</maven.compiler.target>
</properties>
<dependencies>
<!– GWT dependencies (from central repo) –>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<!– <version>${gwt.version}</version>–>
<version>2.0.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<!– <version>${gwt.version}</version>–>
<version>2.0.0</version>
<!– <scope>provided</scope>–>
</dependency>
<!– test –>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<outputDirectory>war/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>generateAsync</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<runTarget>com.theartoftech.gwt20example.Application/Application.html</runTarget>
<source path=”client” excludes=”**/GwtTest*.java” />
</configuration>
</plugin>
<!–
If you want to use the target/web.xml file mergewebxml produces,
tell the war plugin to use it.
Also, exclude what you want from the final artifact here.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>target/web.xml</webXml>
<warSourceExcludes>.gwt-tmp/**</warSourceExcludes>
</configuration>
</plugin>
–>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<mkdir dir=”./war/WEB-INF” />
<copy overwrite=”true” todir=”./war/WEB-INF/”>
<fileset dir=”./src/main/webapp/WEB-INF”>
<include name=”web.xml” />
</fileset>
</copy>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>









