Thursday, June 2, 2016

MAVEN

MAVEN is an innovative software project management tool that provides new concept of a project object model (POM) file to manage project’s build, dependency and documentation. The most powerful feature is able to download the project dependency libraries automatically.

Steps to install MAVEN:-
  • Download the  binary file form apache's site
  • Unzip the zip file and add to the environment variable.
  • To confirm installation use mvn -version on command prompt.
A simple maven project consists of following folder structure
  •  project
    • src
      • main
        • java (the source code)
        • resources
      • test
        • java (the unit test code )
        • resources ()
    • pom.xml (the configuration file containing the information to build the project)
POM.xml stands for Project Object Model and it has the below structure

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>PROJECT_NAME_IN_PACKAGE_NAME_STYLE</groupId>
<artifactId>NAME_OF_JAR</artifactId>
<version>VERSION_OF_JAR</version>
</project>

MVN Install:-
  • It is used to install the package to local repository so that it can be referenced by several projects
MVN package:-
  •  It is used to build the project
mvn archetype:generate:-

To create a java project in java 
mvn archetype:generate
-DgroupId=com.anshul.ws
-DartifactId=MyWebService
-DarchetypeArtifactId=maven-archetype-quickstart
-DinteractiveMode=false

To support eclipse

mvn eclipse:eclipse -Dwtpversion=2.0
Life cycle of Maven:-
Like we have targets in case of Ant , we have phases in maven

Features of MAVEN:-
  • Build process becomes very easy
To create a web-app using maven
  1. Using command prompt go to the directory where project needs to be created
  2. Type below
    mvn archetype:generate -DgroupId=org.arsoft.projects.sood -DartifactId=arsood -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
  3. To be able to access the project on eclipse go to the directory and run command
    mvn eclipse:eclipse -Dwtpversion=2.0
To create a Java project:

mvn archetype:generate -DgroupId=org.arsoft.projects.sood -DartifactId=arsood -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

To create an EJB project:

mvn archetype:generate -DgroupId=com.arsoft.projects -DartifactId=Common -DarchetypeArtifactId=ejb-javaee6 -DinteractiveMode=false

Understanding POM
  1. It stands for Project Object Model and is the fundamental unit of work in maven.

No comments:

Post a Comment

SpringBoot Application Event Listeners

When a spring boot application starts few events occurs in below order ApplicationStartingEvent ApplicationEnvironmentPreparedEvent Applicat...