Introduction
Maven is centered around the concept of POM files (Project Object Model). A POM file is an XML representation of project resources like source code, test code, dependencies (external JARs used) etc. The POM contains references to all of these resources. The POM file should be located in the root directory of the project it belongs to.Here is a diagram illustrating how Maven uses the POM file, and what the POM file primarily contains:
These concepts are explained briefly below to give you an overview, and then in more detail in their own sections later in this tutorial.
POM Files
When you execute a Maven command you give Maven a POM file to execute the commands on. Maven will then execute the command on the resources described in the POM.Build Life Cycles, Phases and Goals
The build process in Maven is split up into build life cycles, phases and goals. A build life cycle consists of a sequence of build phases, and each build phase consists of a sequence of goals. When you run Maven you pass a command to Maven. This command is the name of a build life cycle, phase or goal. If a life cycle is requested executed, all build phases in that life cycle are executed. If a build phase is requested executed, all build phases before it in the pre-defined sequence of build phases are executed too.
Dependencies and Repositories
One of the first goals Maven executes is to check the dependencies needed by your project. Dependencies are external JAR files (Java libraries) that your project uses. If the dependencies are not found in the local Maven repository, Maven downloads them from a central Maven repository and puts them in your local repository. The local repository is just a directory on your computer's hard disk. You can specify where the local repository should be located if you want to (I do). You can also specify which remote repository to use for downloading dependencies. All this will be explained in more detail later in this tutorial
Build Plugins
Build plugins are used to insert extra goals into a build phase. If you need to perform a set of actions for your project which are not covered by the standard Maven build phases and goals, you can add a plugin to the POM file. Maven has some standard plugins you can use, and you can also implement your own in Java if you need to.
Build Profiles
Build profiles are used if you need to build your project in different ways. For instance, you may need to build your project for your local computer, for development and test. And you may need to build it for deployment on your production environment. These two builds may be different. To enable different builds you can add different build profiles to your POM files. When executing Maven you can tell which build profile to use.
Maven uses the concept of the repository to hold the jar files. There are two types of repository namely local and remote repository.
Every maven project has a pom.xml file. If u run Your application with maven then, Now it checks your local repository for the jar files. If the jar files are not found it goes to the remote repository and download the jar. After downloading jars it will Execute life cycle, build phases and/or goals.
First Sample Application:
1. Open Command Prompt [ ctrl+Alt+T ]
$mvn archetype:generate (when you run this for 1st time it download lots of maven plugins )
2. Choose a number (What selection number is )?
There are number of archetype, the number is the specific number of a archetype that is available to use. Then the project structure will form accordingly.
3. Maven pom.xml file
POM is an acronym for Project Object Model. The pom.xml file contains information of project and configuration information for the maven to build the project such as dependencies, build directory, source directory, test source directory, plugin, goals etc. Maven reads the pom.xml file, then executes the goal.
In Our case the generated project has this pom.xml file.
Pom File Tag Description
Contact Us
Visualpath IT Training institute
Flat 205, 2nd floor,Nilgiri block, Aditya Enclave
Ameerpet, Hyderabad - 16
Ph: 9704455959
Email: courseinfo@visualpath.in
www.visualpath.in
Comments
Post a Comment