How to do it...

Follow the steps to create Maven Projects for our succeeding code snippets as follows:

  1. There are two ways that we can create a Maven project from scratch in STS. One option is to right-click the Project Explorer of the IDE in order to choose New | Other... from the pop-up window (or Ctrl-N). The other option is to click the File menu option then choose the New | Other... . Both of these operations will lead us to our New project wizard as shown as follows:
  1. On the menu wizard, click the Maven Module and then the Maven Project option. The New Maven project wizard will pop-up anew. Just click Create Simple Project (skip archetype selection) to create a clean project from scratch:
  1. Afterwards, the next wizard will require you to fill out the necessary Group Id and Artifact Id for your project. In the following example, the Group ID is org.packt.recipe.core and the Artifact Id is, let us say, ch01. The next important field that needs to be filled is Packaging and it must be set to war in our case:
  1. Click Finish. Look for the file pom.xml and insert below it the following lines to correct some Maven bugs:
<build> 
  <finalName>ch01-spring5-cookbook</finalName> 
  <plugins> 
    <plugin> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>2.3</version> 
      <configuration> 
        <failOnMissingWebXml>false</failOnMissingWebXml> 
      </configuration> 
    </plugin> 
  </plugins> 
</build> 
  1. Finally, you must have the directory structure as follows in your own project explorer: