Youtube Channel

Apache Maven

Apache maven is a software project management and comprehension tool  provides developers a complete build life cycle framework.
Maven provides the following;
·         Builds
·         Documentation
·         Reporting
·         Dependencies
·         Release
·         Distribution
Maven can provide benefits for your build process by employing standard conventions and practices to acclerate your  development cycle while at the same time helping you achieve a higer rate of success.
Maven objectives
·         A comprehensive model for project which is reusable, maintainable, and easier to comprehend.
·         Plugin or tools that interact with this declarative model.
Setup maven
1.       download maven from http://maven.apache.org/download.html
2.       extract it to the directory you wish to install maven .
3.       set maven environment variables(M2_HOME,M2,& MAVEN_OPTS)
M2_HOMEàC:\program files\apache software foundation\Apache-maven-2.2.1
M2à%M2_HOME%\bin
MAVEN_OPTSà-xms256m –xmx512(this is optional)
My first maven project in command prompt
·         Required internet connectivity
·         To create first project we are going to use maven’s archetype mechanism
·         An archetype is defined as an original pattern or model from which all other things of the same kind are made.
·         In maven, an archetype is a template of a project which is combined with some user input to produce a working maven project that has ben tailored to users requirements.

In order  to create simple maven projects, execute the following from the command line

Mvn archetype:generate
·         When this command is run for first time maven will download all the plugins and then it will show a list of maven archetypes to choose.
·         The list of archetype contains different technologies and frameworks related project templates.
·         Due to more no of archetypes we cat see all archetypes on screen so, we can apply a filter to see the related archetypes only.
·         After selecting an archetype then it will prompt to enter group id,artifact id, version, package.
·         After confirming the given details maven creates a folder structure of the selected project archetype.
Mvn compile
·         This command will compile source files and places it under target/classes folder of the project
Mvn package
·         This command will prepare jar,war,ear file for the project , depends on archetype of the project.
Mvn install
·         This command is optional to run and will store or install the packaged jar , war,ear file to local maven repository
·         Repository is a place where all downloaded jar files or plugins will be stored.
·         Maven downloads plugins or jars from central repository and placed it to local repository on the developers machine.
·         You can find local repository in your machine via c:/documents and settings/myfolder(system name)/.m2/repository
Example :
The following is a step by step process of creating a standalone project in maven
C:>mvn archetype:generate
A list of archetypes will be displayed . type a word  ‘QuickStart’. Identify maven-archetype-QuickStart in displayed list and enter its no . for example 3.
Choose a no:6   (highest version)
Group id:pack1 (package name)
Artifact id:DemoApp      (project name)
Version:               (leave it blank press enter)
Package:              (leave it blank press enter)
Y:Y
Now following project structure will be created


Now compile the program
C:>\DemoApp>mvn compile
Now maven creates a traget directory and stores the .class file
C:\DemoApp>mvn package
Now jar file will be created in the project directory with name DemoApp-1.0-SNAPSHOT.jar
Now run the application by following command
C:>DemoApp>java –cp target\DemoApp-1.0-SNAPSHOT.jar pack1.App
 OUTPUT: HELLO WORLD







Next PostNewer Post Previous PostOlder Post Home