Fork me on GitHub

Processing Annotation @RemoteServiceRelativePath to generate web.xml content

Because life is too short to manually write xml content for servlets in web.xml files (and not everybody uses servlet 3.0), you can now automatically merge your web.xml with generated servlet lines for classes annotated with @RemoteServiceRelativePath. This feature has been added in mergewebxml mojo

<project>
  [...]
  <build>
    <plugins>
      [...]
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>gwt-maven-plugin</artifactId>
        <version>${pom.version}</version>
        <configuration>
          <packageNamePerModule>
            <hello>org.codehaus.mojo.gwt.test.server</hello>
          </packageNamePerModule>
          <scanRemoteServiceRelativePathAnnotation>true</scanRemoteServiceRelativePathAnnotation>
        </configuration>
        <executions>
          <execution>
            <id>mergewebxml</id>
            <phase>process-classes</phase>
            <goals>
              <goal>mergewebxml</goal>
            </goals>
          </execution>          
        </executions>
      </plugin>
      [...]
    </plugins>
  </build>
  [...]
</project>

As the the annotation processing need the compiled classes you need to bind the mojo to at least compile phase. The other mojo parameters are :

  • scanRemoteServiceRelativePathAnnotation : to activate this feature
  • packageNamePerModule : to configure per module the root package to scan. Here you can use the "module name" ( org/codehaus/mojo/gwt/test/Hello.gwt.xml -> org.codehaus.mojo.gwt.test.Hello) or the rename-to value coming from your module name.