Maven
·
Build tool
·
Project management tool
Common problems and
activities
·
In managing multiple jars
·
In managing Dependencies and Versions
·
In managing Project structure
·
Used for Building, Publishing and Deployement
Download the latest
maven from below URL.
In my case I have downloaded "apache-maven-3.0.5-bin.zip"
Steps to flow for
installing maven
1. Extract the zip file
2. Set below Environment variables (Windows 7)
M2_HOME
= C:\java\apache-maven-3.0.5
PATH =
C:\java\apache-maven-3.0.5\bin or C:\java\apache-maven-3.0.5\bin;%PATH%
3. Go to command prompt Run-> cmd
4. check maven version using command -> mvn --version
5. Make sure your command should be on bin path eg: C:>java>apache-maven-3.0.5
6. Create directory using command -> mkdir myapp
7. Go into "myapp" direction using command ->
eg: C:>java>apache-maven-3.0.5>myapp>
8. Now type "mvn
archetype:generate" and enter,
It will prompt to
choose a number which is nothing but archeType(Project Type). In my case it is 264
Now it will prompt
with different version, choose latest version. In my case I have choosen 6
It creates project
with all the dependencies available in settings.xml
9. Now it asks for groupId,
which is nothing but package name eg:
org.yash.javajadhav
10. Now it asks for artifactId,
which is nothing but Classname eg: MavenTestApp
11. Now it prompt with Snapshot version, in my case it is 1.0-SNAPSHOT - Don't type anything just press enter
12. Now it prompt with package
, in my case it is org.yash.javajadhav -
Don't type anything just press enter
11. Now it prompt - you want to continue - y / no - n
Now the project will be created at below path
C:\java\apache-maven-3.0.5\myapp\MavenTestApp
It contains src
directory and pom.xml
src contains two
directories they are
·
main which contains application.
·
test which contains test application like junit
pom.xml contains
the information about the application itself and what the dependencies are
In my case it has only dependency i.e. junit
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
We just need to add
first entry point of dependency all remaining jars will be taken care by Maven
Compile our application using below command
mvn complie
Make sure you will be in application directory (C:\java\apache-maven-3.0.5\myapp\MavenTestApp)
Now we require packages, type below command
mvn package
It will create “MavenTestApp-1.0-SNAPSHOT.jar”
in target directory
Now we have jar, lets execute it using below command.
Java -cp target/MavenTestApp-1.0-SNAPSHOT.jar
org.yash.javajadhav.App
Maven gets all its knowledge from maven repository
It has two type of information they are 1.ArchetypeInfo 2.Dependency Info
Archetype Info:
Has information about different types of projects you want to create, folder
structure and all the required information creating a new project of that particular
type
Dependency info:
Has information about list of all the jars.
No comments:
Post a Comment