You are on page 1of 2

How to install maven

1- Download maven from www.maven.apache.org(go to download section and download


a "apache-maven-3.2.2-bin-zip" version)
2- Save it and unzip it.
3- Set environment variable
a- MAVEN_HOME = path upto home folder of maven(E:\Program Files\apache-m
aven-3.2.2)
b- JAVA_HOME = path upto home folder of jdk(E:\Program Files\Java\jdk1.7
.0_60)
c- Set path = E:\Program Files\apache-maven-3.2.2\bin
4- Save this
5- Now check whether maven install or not, open command promt and write "mvn"
6- If it execute properly, i.e., maven install successfully.
Writing first program in
maven
1- Make a folder in your comuter any where you want(I make with name "app").
2- Within that folder make a folder name as "src"(you can't choose another name
it fixed)
3- Make a xml file within "app" with name "pom.xml".(Below i providing the basic
of "pom.xml" for any maven program)
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.lara</groupId>
<artifactId>app1</artifactId>
<version>1.0</version>
</project>
4- Make another folder in src with name as main and a folder with name test.
main- It contains main resorces of project.
Name "main" is an industry convension.
test- This folder is to develope test resorces.
Name "test" is an industry convension.
5- Create another two folder within main folder named "java" and "resorces"
java- It contain program file or packages whom you create for your pr
oject.
resorces- It contain file like properties,xml or other files which we
nead in our project.
6- Now write your java code and save it into packages whom you create.
7- Now for compiling and also for run mavan first time you need internet connect
ion(becouse when we compile or run maven first time it require some file to down
load from internet)
8- To compile maven program write commamd "mvn compile" in command promt.
9- TO run maven you write command "mvn exec:java -Dexec.mainClass='your package
name'.'.java file name' "
ex: mvn exec:java -Dexec.mainClass=com.lara.A
com.lara is my pacakge and A is my .java file
10- You can also create jar file by writing command "mvn jar:jar"
To whether you jar file create or not goto "app" inside that a file name
as "target" is created, inside that a jar file is created
by default the name of that jar file is name of your project and version
of the project. ("app1-1.0.jar")
11- You can also make a javadoc for you project. Using "mvn javadoc:javadoc"
To check your generate javadoc goto target folder, you will find there a
folder name as "site".It means your javadoc is created.
To read your javadoc go "site\apidoc\index.html".
(All of the above command line instruction what ever we were doing one by one yo
u can do it together by writing - "mvn compile exec:java -Dexec.mainClass=com.la
ra.A jar:jar javadoc:javadoc")

You might also like