Contents

pom.xml: telling Maven what to do

The pom.xml file that Eclipse generated is a very basic POM. We are going to need more than that for our project. Let's add some information to the pom file, so that Maven knows what to do with our project.

Copy the following contents to your pom.xml file.

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>net.tekstenuitleg</groupId>
    <artifactId>my-spring-app</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>My Spring MVC Application</name>
 
    <properties>
        <org.springframework.version>3.1.0.RELEASE</org.springframework.version>
    </properties>
 
 
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
    </dependencies>
 
    <build>
        <finalName>ROOT</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

If you know Maven, most of this will speak for itself. If you don't know Maven that well, read on.

The groupId, artifactId and version together identify the application. 

I included the packaging tag and set it to "war". This will cause Maven to generate a war file instead of the default jar file.

Also, I included dependencies for spring-context and spring-webmvc, as we'll need these later on to turn this into a Spring MVC application.

The dependency on log4j is obviously needed for logging.

The finalName tag is set to ROOT. This will cause the Maven compiler pluging to create a file called ROOT.war. I prefer ROOT, because I want to  deploy my application as the root application in Tomcat. If you have different preferences you can specify a different name and publish your application in a subdirectory ot the root, BUT, be sure to keep this in mind later when we configure web.xml.

 And finally I included the maven-compiler-plugin to set the target version to Java 1.6.