Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Spring 5.0 Cookbook

You're reading from   Spring 5.0 Cookbook Recipes to build, test, and run Spring applications efficiently

Arrow left icon
Product type Paperback
Published in Sep 2017
Publisher Packt
ISBN-13 9781787128316
Length 670 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Sherwin John C. Tragura Sherwin John C. Tragura
Author Profile Icon Sherwin John C. Tragura
Sherwin John C. Tragura
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Getting Started with Spring FREE CHAPTER 2. Learning Dependency Injection (DI) 3. Implementing MVC Design Patterns 4. Securing Spring MVC Applications 5. Cross-Cutting the MVC 6. Functional Programming 7. Reactive Programming 8. Reactive Web Applications 9. Spring Boot 2.0 10. The Microservices 11. Batch and Message-Driven Processes 12. Other Spring 5 Features 13. Testing Spring 5 Components

Creating Eclipse projects using Maven

One option for creating our Spring 5.0 projects is through Maven. The STS Eclipse 3.8 has built-in Maven plugins that will create Maven-ready Eclipse projects easily.

Getting started

Before creating the first Maven project, check first the JRE workspace configuration of your IDE. As noted in the previous recipe, the JRE of your Eclipse must be set to the JDK's JRE. Moreover, check the embedded version of Maven installed in STS Eclipse 3.8 through the Windows | Preferences panel. STS 3.8 will be using its embedded Maven 3.0 for the deployment operations. The list of Maven versions is available at https://maven.apache.org/.

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:

How it works...

Apache Maven is already a built-in plugin in Eclipse and helps developers manage projects and use some build tools to clean, install, and deploy Eclipse projects. It has the main configuration file which is called the Project Object Model (POM) file.

POM is the fundamental unit of work in Maven that contains information and configuration details about the project. Some core information in POM is <modelVersion>, which currently must be set to 4.0.0, <groupId>, that identifies the project uniquely together with <projectId> and <versionId> across all projects in the Maven repository, <artifactId>, which is the name of the WAR file without the version, and <packaging>, which is WAR.

Later in this book, we will be adding <properties> and <dependencies> and <plugins> for our Spring 5.0 code recipes in our pom.xml file.

You have been reading a chapter from
Spring 5.0 Cookbook
Published in: Sep 2017
Publisher: Packt
ISBN-13: 9781787128316
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime