MAVEN
Table of Contents
MAVEN: What is MAVEN?
MAVEN : What is POM?
MAVEN : Why we need MAVEN?
MAVEN VS ANT
MAVEN installation on WINDOW
MAVEN Build Lifecycle
MAVEN Repository
MAVEN Plugins, Dependencies, External Dependency, Project Documents
MAVEN Folder Structure
MAVEN commands
MAVEN Project from console
MAVEN project using eclipse
MAVEN Project from java project using eclipse
MAVEN Web Project
MAVEN: What is MAVEN?:
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
MAVEN : What is POM?
As a fundamental unit of work in Maven, POM is an XML file that contains information about project and configuration details used by Maven to build the project
MAVEN : Why we need MAVEN?
Making the build process easy
Providing a uniform build system
Providing quality project information
Providing guidelines for best practices development
Allowing transparent migration to new features
Common Problem
Multiple jarsdependencies and version
Project structure
Building , polishing and deploying
MAVEN VS ANT
One level above ANTHigher level of reusability between builds
Faster turn around time to set up a powerful build
Less maintenance
Repository management
Automatic downloads
MAVEN installation on WINDOW
MAVEN Build Lifecycle
Maven defines 3 lifecycles
default Lifecycle
clean Lifecycle
site Lifecycle
Clean Lifecycle
pre-clean execute processes needed prior to the actual project cleaning
clean remove all files generated by the previous build
post-clean execute processes needed to finalize the project cleaning
Default Lifecycle
validate validate the project is correct and all necessary information is available.
initialize initialize build state, e.g. set properties or create directories.
generate-sources generate any source code for inclusion in compilation.
process-sources process the source code, for example to filter any values.
generate-resources generate resources for inclusion in the package.
process-resources copy and process the resources into the destination directory, ready for packaging.
compile compile the source code of the project.
process-classes post-process the generated files from compilation, for example to do bytecode enhancement on Java classes.
generate-test-sources generate any test source code for inclusion in compilation.
process-test-sources process the test source code, for example to filter any values.
generate-test-resources create resources for testing.
process-test-resources copy and process the resources into the test destination directory.
test-compile compile the test source code into the test destination directory
process-test-classes post-process the generated files from test compilation, for example to do bytecode enhancement on Java classes. For Maven 2.0.5 and above.
test run tests using a suitable unit testing framework. These tests should not require the code be packaged or deployed.
prepare-package perform any operations necessary to prepare a package before the actual packaging. This often results in an unpacked, processed version of the package. (Maven 2.1 and above)
package take the compiled code and package it in its distributable format, such as a JAR.
pre-integration-test perform actions required before integration tests are executed. This may involve things such as setting up the required environment.
integration-test process and deploy the package if necessary into an environment where integration tests can be run.
post-integration-test perform actions required after integration tests have been executed. This may including cleaning up the environment.
verify run any checks to verify the package is valid and meets quality criteria.
install install the package into the local repository, for use as a dependency in other projects locally.
deploy done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.
Site Lifecycle
pre-site execute processes needed prior to the actual project site generation
site generate the project's site documentation
post-site execute processes needed to finalize the site generation, and to prepare for site deployment
site-deploy deploy the generated site documentation to the specified web server
MAVEN Repository
Local repository
Central repository
Remote repository
MAVEN commands
The goal you indicate in the command line is linked to the lifecycle of Maven.
For example, the build lifecycle (you also have the clean and site lifecycles which are different) is composed of the following phases:
validate: validate the project is correct and all necessary information is available.
compile: compile the source code of the project.
test: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed.
package: take the compiled code and package it in its distributable format, such as a JAR.
integration-test: process and deploy the package if necessary into an environment where integration tests can be run.
verify: run any checks to verify the package is valid and meets quality criteria
install: install the package into the local repository, for use as a dependency in other projects locally.
deploy: deploy in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.
MAVEN Project from console
mvn archetype:generate -DgroupId=com.bebo -DartifactId=MyProject -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
-DarchetypeArtifactId=maven-archetype-quickstart
-DarchetypeArtifactId=maven-archetype-webapp
MAVEN Folder Structure
MAVEN project using eclipse
Assignment:
Setup Maven on your system. create your local repo on D drive
Create Maven project using console && convert it to eclipse using console && import to eclipse.
Create java web or java project using eclipse, convert it to maven project && add dependency, verify dependencies from your local repo.