Child pages
  • Create A Spring Web App Using Maven
Skip to end of metadata
Go to start of metadata

Overview

This document describes how to create a basic web app using Maven.

Create The Project

Type the following maven command at the command prompt. Replace -DgroupId and -DartifactId with information specific to your group and your project, respectively.

mvn archetype:create -DgroupId=coedu.ucsf.oaais.myaccess.spring -DartifactId=mywebapp -DarchetypeArtifactId=maven-archetype-webapp

Configure Jetty

Now edit the pom.xml file and add the Jetty plugin. Jetty is a HTTP server and javax.servlet container, and the Jetty Maven Plugin allows you to run your project in Jetty using maven.

Add the following XML to the <build> section of pom.xml:

<plugins>
      <plugin>
              <groupId>org.mortbay.jetty</groupId>
              <artifactId>maven-jetty-plugin</artifactId>
              <version>6.1.10</version>
              <configuration>
                      <scanIntervalSeconds>10</scanIntervalSeconds>
                      <stopKey>foo</stopKey>
                      <stopPort>9999</stopPort>
              </configuration>
              <executions>
                      <execution>
                              <id>start-jetty</id>
                              <phase>pre-integration-test</phase>
                              <goals>
                                      <goal>run</goal>
                              </goals>
                              <configuration>
                                      <scanIntervalSeconds>0</scanIntervalSeconds>
                                      <daemon>true</daemon>
                              </configuration>
                      </execution>
                      <execution>
                              <id>stop-jetty</id>
                              <phase>post-integration-test</phase>
                              <goals>
                                      <goal>stop</goal>
                              </goals>
                      </execution>
              </executions>
      </plugin>
    </plugins>

Once you have done that, you can now run your newly created project in Jetty. From the root directory of the project, type:

mvn jetty:run-war

Now check out your app by going to: http://localhost:8080.

Set Up Project In Eclipse

Now that the project has been created, tell maven that this is an Eclipse project.

cd mywebapp
mvn eclipse:eclipse

Note: If you want to use Intellij IDEA, you can do the following:

mvn idea:idea

Documentation on how to set up your project with Intellij and NetBeans can be found on the appfuse.org website: http://appfuse.org/display/APF/IDEA and http://appfuse.org/display/APF/NetBeans.

Now, import your project into Eclipse:

From Eclipse go to File > Import > Existing Projects into Workspace (under the General category). Select the root directory of your project. Click Finish, and you now have your project set up in Eclipse.

More detailed information about how to fully set up Eclipse for this project can be found on the appfuse.org site: http://appfuse.org/display/APF/Eclipse

Build The Project

Now that you have the project set up and ready to go, you will want to build the .war file. To do this you must "install" the app:

mvn install

Once this is complete, you will see a new directory called target an inside of it will be mywebapp.war.

Make the Project a Spring Project

Now that the basics have been covered, let's actually make this project a Spring project by adding the Spring framework dependencies to the pom.xml file.

Clean Up

Before you build a maven project it is always best to clean the project first. To do this just type:

mvn clean
  • No labels