Apache Maven Is a Software Project Management and Comprehension Tool
Total Page:16
File Type:pdf, Size:1020Kb
About the Tutorial Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information. Using maven we can build and manage any java based project. This tutorial will teach you how to use Maven in your day-to-day life of any project development using Java. Audience This tutorial has been prepared for the beginners to help them understand the basic functionality of Maven tool. After completing this tutorial you will find yourself at a moderate level of expertise in using Apache Maven from where you can take yourself to next levels. Prerequisites We assume you are going to use Maven to handle enterprise level Java projects development. So it is beneficial to have the knowledge of software development, Java SE, overview of Java EE development and deployment process. Copyright and Disclaimer Copyright 2019 by Tutorials Point (I) Pvt. Ltd. All the content and graphics published in this e-book are the property of Tutorials Point (I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish any contents or a part of contents of this e-book in any manner without written consent of the publisher. We strive to update the contents of our website and tutorials as timely and as precisely as possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our website or its contents including this tutorial. If you discover any errors on our website or in this tutorial, please notify us at [email protected] i Table of Contents About the Tutorial ...................................................................................................................................... Audience .................................................................................................................................................... i Prerequisites .............................................................................................................................................. i Copyright and Disclaimer ........................................................................................................................... i Table of Contents ...................................................................................................................................... ii 1. APACHE MAVEN — OVERVIEW ......................................................................................... 1 What is Maven? ........................................................................................................................................ 1 Maven Evolution ....................................................................................................................................... 1 Objective .................................................................................................................................................. 2 Convention over Configuration ................................................................................................................. 2 Features of Maven .................................................................................................................................... 3 2. APACHE MAVEN — ENVIRONMENT SETUP ........................................................................ 4 System Requirement................................................................................................................................. 4 3. APACHE MAVEN — POM .................................................................................................. 9 Super POM .............................................................................................................................................. 10 4. APACHE MAVEN — BUILD LIFE CYCLE ............................................................................. 17 What is Build Lifecycle?........................................................................................................................... 17 Clean Lifecycle ........................................................................................................................................ 18 Default (or Build) Lifecycle ...................................................................................................................... 21 Site Lifecycle ........................................................................................................................................... 26 5. APACHE MAVEN — BUILD PROFILES ............................................................................... 30 What is Build Profile? .............................................................................................................................. 30 Types of Build Profile .............................................................................................................................. 30 ii Profile Activation .................................................................................................................................... 30 Profile Activation Examples .................................................................................................................... 30 Explicit Profile Activation ........................................................................................................................ 31 Profile Activation via Maven Settings ..................................................................................................... 34 Profile Activation via Environment Variables .......................................................................................... 35 Profile Activation via Operating System .................................................................................................. 36 Profile Activation via Present/Missing File .............................................................................................. 36 6. APACHE MAVEN — REPOSITORIES .................................................................................. 38 What is a Maven Repository? ................................................................................................................. 38 Local Repository...................................................................................................................................... 38 Central Repository .................................................................................................................................. 39 Remote Repository ................................................................................................................................. 39 Maven Dependency Search Sequence ..................................................................................................... 40 7. APACHE MAVEN — PLUGINS .......................................................................................... 42 What are Maven Plugins? ....................................................................................................................... 42 Plugin Types ............................................................................................................................................ 42 8. APACHE MAVEN — CREATING JAVA PROJECT .................................................................. 46 9. APACHE MAVEN — BUILD AND TEST JAVA PROJECT ........................................................ 51 Adding Java Source Files ......................................................................................................................... 53 10. APACHE MAVEN — EXTERNAL DEPENDENCIES ................................................................ 56 11. APACHE MAVEN — PROJECT DOCUMENTS ..................................................................... 59 12. APACHE MAVEN — PROJECT TEMPLATES ........................................................................ 62 What is Archetype? ................................................................................................................................. 62 Using Project Template ........................................................................................................................... 62 iii Created Project ....................................................................................................................................... 64 Created POM.xml.................................................................................................................................... 65 Created App.java .................................................................................................................................... 66 Created AppTest.java .............................................................................................................................. 66 Different Archetypes ............................................................................................................................... 68 13. APACHE MAVEN — SNAPSHOTS ..................................................................................... 70 What is SNAPSHOT? ................................................................................................................................ 70 Snapshot vs Version ................................................................................................................................ 70 app-ui