Creating the project with Maven

The first use of Maven is to automate the Java project's creation. The procedure for creating a basic project is the same as for Java EE and Spring. Project configuration, and types and amounts of dependencies, are different for each of them. We will see an example usage of Maven in next section, that is  Your very first Microservice.

To create a project, the mvn archetype:generate command can be used. This command requires the project name as input:

  • groupId: This identifies the project across all other projects. Often, a reversed domain name is used.
  • artifactId: This represents the name of the project.
  • version: This can be omitted. The default value is 1.0-SNAPSHOT.

The following code shows a sample Maven generate command:

mvn archetype:generate 
-DgroupId=com.packtpub.microservices
-DartifactId=weather-service
-DinteractiveMode=false

A folder named after the artifactId property is created by Maven. In this case, it is the weather-service folder. This a folder created by Maven is referred to as .{project-root} throughout the book. In .{project-root}, a simple file structure is to be found, which is shown here:

.{project-root}
├── pom.xml
└── src

The pom.xml file describes project properties and required libraries. Also, the packaging of the Microservice is defined in this file. In the src/ folder, the source code of the Microservice will reside.

For the sake of simplicity, there are many nuances of Maven that are not explained in this book. The ways of generating a project with Maven are countless. Visit maven.apache.org to obtain a detailed introduction to Maven. In the Introduction guide, the basic concepts are explained, including the reasoning behind archetypes, snapshot versions, and naming conventions.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.203.96