Using Maven is alot easier than using some of the other build tools like Ant.
Why choose Maven over Ant?
In Ant, we have to manually copy all the dependencies to the project location when setting up the project, whereas in Maven, all the dependencies are downloaded recursively and automatically during the project set up from a central repository where all the files are stored. This in turn reduces the project set up time too.
Another advantage would be what was mentioned at the top: Maven uses "Convention over Configuration" whereas in Ant, we have to configure alot of stuff manually.
How to setup Maven
Maven can be configured at any place, and use the following link provided to download the zip file of Maven:
http://redrockdigimark.com/apachemirror/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.zip
After downloading, you have to configure two environment variables.
To do this, search environment variables in your computer, and choose Edit the system environment variables-->Click Environment Variables... from the window that appears, then under the system variables:
- Add New variable named MAVEN_HOME or M2_HOME and for the value give the path to the home directory of Maven in your extracted file.
- Select and Edit the Path variable, and add New path to the bin folder in your extracted Maven home directory.
As the next step, we will check whether Maven is working now by giving the command:
mvn -v
This should work now, given that the Java environment configurations have already been done. If you get a problem configure JAVA_HOME by giving path to Java installed home directory and add the path to the bin folder of Java folder to the Path variable.
If it works properly you should get an output which includes Maven home, Java version, and Java home with some other details.
How to create a simple project using Maven
Give the following command to create a project using Maven:
mvn archetype:generate -DgroupId=com.student.learn
-DartifactId=learnMaven -DarchetypeArtifactId=maven-archetype- quickstart
Note that archetype is a templating toolkit used to create projects of the same kind.
- groupId will be the name of the package of your project.
- artifactId will be the name of the project.
- archetypeArtifactId indicates which archetype to be used when setting up the project through its name.
Give appropriate values to these three attributes as you want.
No comments:
Post a Comment