First of all, I noticed that when you're using the GWT Maven Plugin with a JAR project, it doesn't automatically run gwt:compile or gwt:test in the compile and test phases. I had to explicitly configure the compile goal to run in the compile phase. I also had to add <webappDirectory> to the configuration to compile the JavaScript files into the war directory.
<plugin><groupId>org.codehaus.mojo</groupId><artifactId>gwt-maven-plugin</artifactId><version>1.1</version><configuration><module>org.appfuse.gwt.core.CoreUI</module><runTarget>index.html</runTarget><webappDirectory>war</webappDirectory></configuration><executions><execution><phase>compile</phase><goals><goal>compile</goal></goals></execution></executions></plugin>
To package the generated JavaScript and index.html in the JAR, I added the following <resources> section to the maven-resources-plugin configuration I mentioned in my previous post.
<resource><directory>war</directory><includes><include>core.ui/**</include><include>index.html</include></includes></resource>
In addition, I discovered some javax.servlet.* classes in my JAR after running "mvn package". I believe this is caused by the GWT plugin sucking these in when it compiles my ProxyServlet. I excluded them by adding the maven-jar-plugin.
<plugin><artifactId>maven-jar-plugin</artifactId><configuration><excludes><exclude>javax/servlet/**</exclude></excludes></configuration></plugin>
After doing this, I was able to publish my JAR with all the contents I needed to run Selenium tests against it.
Testing the GWT Library with Selenium
The module that contains the Selenium tests is a WAR project that uses war overlays, Cargo and Selenium RC. You can read about the Maven setup I use for running Selenium tests in Packaging a SOFEA Application for Distribution.
The major difference when testing a JAR (vs. a WAR), is I had to use the maven-dependency-plugin to unpack the JAR so its contents would get included in the WAR for testing. Below is the configuration I used to accomplish this:
<plugin><artifactId>maven-dependency-plugin</artifactId><executions><execution><id>unpack</id><phase>generate-sources</phase><goals><goal>unpack</goal></goals><configuration><artifactItems><artifactItem><groupId>org.appfuse</groupId><artifactId>gwt-core</artifactId><version>1.0-SNAPSHOT</version><type>jar</type><overWrite>false</overWrite><excludes>META-INF/**,org/**,javax/**</excludes></artifactItem></artifactItems><outputDirectory> ${project.build.directory}/${project.build.finalName}</outputDirectory></configuration></execution></executions></plugin>
Hopefully this will help you develop GWT libraries and run Selenium tests against them. If you have any suggestions for simplifying this configuration, please let me know.
NOTE: I did considering a couple of other options for running Selenium tests against our GWT library:
- Add something to the existing project that 1) creates a WAR and 2) fires up Cargo/Selenium in a profile to test it.
- Create the tests in a GWT (war) project that includes widgets from the library.
I decided on the solution documented above because it seemed like the best option.