Using Maven for project management

In the projects that we have created thus far in this chapter, we have managed many project management tasks, such as downloading libraries on which our project depends, adding them to the appropriate folder so that the web application can find it, and exporting the project to create the WAR file for deployment. These are just some of the project management tasks that we have performed so far, but there are many more, which we will see in the subsequent chapters. It helps to have a tool do many of the project management tasks for us so that we can focus on application development. There are some well-known build management tools available for Java, for example, Apache Ant (http://ant.apache.org/) and Maven (http://maven.apache.org/).

In this section, we will see how to use Maven as a project management tool. By following the convention for creating the project structure and allowing projects to define the hierarchy, Maven makes project management easier than Ant. Ant is primarily a build tool, whereas Maven is a project management tool, which does build management too. See http://maven.apache.org/what-is-maven.html to understand what Maven can do.

In particular, Maven simplifies dependency management. In the JSF project earlier in this chapter, we first downloaded the appropriate .jar files for JSF and copied them to the lib folder. Maven can automate this. You can configure Maven settings in pom.xml. POM stands for Project Object Model.

Before we use Maven, it is important to understand how it works. Maven uses repositories. Repositories contain plugins for many well-known libraries/projects. A plugin includes the project configuration information, .jar files required to use this project in your own project, and any other supporting artifacts. The default Maven repository is a collection of plugins. You can find the list of plugins in the default Maven repository at http://maven.apache.org/plugins/index.html. You can also browse the content of the Maven repository at http://search.maven.org/#browse. Maven also maintains a local repository on your machine. This local repository contains only those plugins that your projects have specified dependencies on. On Windows, you will find the local repository at C:/Users /<username>.m2, and on macOS X, it is located at ~/.m2.

You define plugins on which your project depends in the dependencies section of pom.xml (we will see the structure of pom.xml shortly when we create a Maven project). For example, we can specify a dependency on JSF. When you run the Maven tool, it first inspects all dependencies in pom.xml. It then checks whether the dependent plugins with the required versions are already downloaded in the local repository. If not, it downloads them from the central (remote) repository. You can also specify repositories to look in. If you do not specify any repository, then dependencies are searched in the central Maven repository.

We will create a Maven project and explore pom.xml in more detail. However, if you are curious to know what pom.xml is, then visit http://maven.apache.org/pom.html#What_is_the_POM.

Eclipse JEE version has Maven built-in, so you don't need to download it. However, if you plan to use Maven from outside Eclipse, then download it from http://maven.apache.org/download.cgi

..................Content has been hidden....................

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