Good old servlets are getting a facelift in the next major version of Java EE after been somewhat neglected for so long.
One of the major changes of the new Servlet 3.0 API is that a web.xml is no longer required. Instead, servlets can be configured directly in the source code via annotations.
I wanted to try out this new feature, deploying in GlassFish 3 preview, which is the only Java EE 6 compliant application server at the moment.
As usual, I created a Maven project to test out this functionality, unfortunately, nobody has told Maven that a web.xml is no longer required. My build was failing with Maven complaining about the lack of a web.xml.
After some research, I found out how to configure Maven to avoid it complaining about this non issue.
Here is my pom.xml in it's entirety.
<project xmlns="http://maven.apache.org/POM/4.0.0"Notice that I'm using the Maven war plugin version 2.1 (in beta at the moment), since previous versions of the plugin (like the default 2.0) do not support the <failOnMissingWebXml> tag yet.
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">
<modelVersion>4.0.0</modelVersion>
<groupId>net.ensode.glassfishbook</groupId>
<artifactId>simpleapp</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>simpleapp</name>
<url>http://maven.apache.org</url>
<build>
<finalName>simpleapp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1-beta-1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>java.net</id>
<url>http://download.java.net/maven/2</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
In my opinion, it's only a temporary solution.
This solution is similar for adding the support of EJB3.0, you have to add additional information for telling to Maven that your are working on JEE5 or JEE6.
In the future, hopefully!, working on JEE5 or JEE6 should be the default behavior. An other solution should be to provide additional life cycles for JEE5 or JEE6 like:
<packaging>warjee5</packaging>
<packaging>warjee6</packaging>
Posted by Gregory Boissinot on September 27, 2009 at 10:43 AM EDT #