What is Maven?
Apache Maven is a java based software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information. Maven provides the complete build lifecycle framework for project management. Development team can automate the project's build infrastructure in almost no time as Maven uses a standard directory layout and a default build lifecycle.
In abstract, Maven simplifies and standardizes the project build process. It handles compilation, distribution, documentation, team collaboration and other tasks seamlessly. Maven increases re-usability and takes care of most of build related tasks
1. Build process
The "Build" is a process that covers all the steps required to create a deliverable product of your software into preproduction and production. In the Java world, this typically includes:1. Generating source.
2. Compiling sources.
3. Executing tests (unit tests, integration tests, etc).
4. Packaging (into jar, war, ejb-jar, ear).
5. Running health checks (static analyzers like Checkstyle, Findbugs, PMD, test coverage, etc).
6. Generating reports.
A defined build process is an essential part of any development cycle because it helps close the gap between the development, integration, test, and production environments. A build process alone will speed the migration of software from one environment to another. It also removes many issues related to compilation, classpath, or properties that cost many projects time and money.
2. What is a Build Tool?
A build tool is a tool that automates everything related to building the software project. Building a software project typically includes one or more of these activities:1. Generating source code (if auto-generated code is used in the project).
2. Generating documentation from the source code.
3. Compiling source code.
4. Packaging compiled code into JAR files or ZIP files.
5. Installing the packaged code on a server, in a repository or somewhere else.
Any given software project may have more activities than these needed to build the finished software. Such activities can normally be plugged into a build tool, so these activities can be automated too.
The advantage of automating the build process is that you minimize the risk of humans making errors while building the software manually. Additionally, an automated build tool is typically faster than a human performing the same steps manually.
3. Understanding the common problem without Maven
There are many problems that we face during the project development. They are discussed below:- Adding set of Jars and dependencies in each project: In case of struts, spring, hibernate frameworks, we need to add set of jar files in each project. It must include all the dependencies of jars also.
- Creating and maintaining the right project structure: We must create the right project structure in servlet, struts etc, otherwise it will not be executed.
- Building and Deploying the project: We must have to build and deploy the project so that it may work.
Compilation and execution
Compilation and execution of a Java program is two step processes. During compilation phase Java compiler compiles the source code and generates byte code. This intermediate byte code is saved in form of a .class file. In second phase, Java virtual machine (JVM) also called Java interpreter takes the .class as input and generates output by executing the byte code.Various build tools available:
1. For java - Ant,Maven,Gradle.
2. For .NET framework - NAnt
3. C# - MsBuild.
Comparison between few Java based Build Tools:
Ant vs Maven vs Gradle:
Ant
Apache Ant is a Java library and command-line tool whose mission is to drive processes described in build files as targets and extension points dependent upon each other. The main known usage of Ant is the build of Java applications. Ant supplies a number of built-in tasks allowing to compile, assemble, test and run Java applications. Ant can also be used effectively to build non Java applications, for instance C or C++ applications. More generally, Ant can be used to pilot any type of process which can be described in terms of targets and tasks.
It has very low learning curve thus allowing anyone to start using it without any special preparation. It is based on procedural programming idea. After its initial release, it was improved with the ability to accept plug-ins. Major drawback was XML as the format to write build scripts. XML, being hierarchical in nature, is not a good fit for procedural programming approach Ant uses. Another problem with Ant is that its XML tends to become unmanageable big when used with all but very small projects.
Maven
Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information. Its goal was to improve upon some of the problems developers were faced while using Ant. Maven continues using XML as the format to write build specification. However, structure is diametrically different.
While Ant requires programmer to write all the commands that lead to the successful execution of some task whereas Maven relies on conventions and provides the available targets (goals) that can be invoked. As the additional, and probably most important addition, Maven introduced the ability to download dependencies over the network (later on adopted by Ant through Ivy). Main benefit from Maven is its life-cycle. As long as the project is based on certain standards, with Maven one can pass through the whole life cycle with relative ease. This comes at a cost of flexibility.
Now the interest for DSLs (Domain Specific Languages) continued increasing. The idea is to have languages designed to solve problems belonging to a specific domain. In case of builds, one of the results of applying DSL is Gradle and for e.g. gradle is used in Android for build and packaging.
Gradle
Gradle aims to help organizations ship better software, faster. Faster builds is one of the most direct ways of achieving this Gradle combines good parts of both tools and builds on top of them with DSL and other improvements. It has Ant’s power and flexibility with Maven’s life-cycle and ease of use. For example, Google adopted Gradle as the default build tool for the Android OS.
Gradle does not use XML. Instead, it had its own DSL based on Groovy (one of JVM languages). As a result, Gradle build scripts tend to be much shorter and clearer than those written for Ant or Maven. The amount of boilerplate code is much smaller with Gradle since its DSL is designed to solve a specific problem: move software through its life cycle, from compilation through static analysis and testing until packaging and deployment.
Maven simplifies and give solution to the above-mentioned problems. It performs mainly following tasks.
1. It makes a project easy to build
2. It provides uniform build process (maven project can be shared by all the maven projects)
3. It provides project information (log document, cross referenced sources, mailing list, dependency list, unit test reports etc.)
4. It is easy to migrate for new features of Maven
Uses of Apache Maven
1. Use as Build Tool
2. Use as to manage Project structure
3. Building, publishing and deploying
4. Documentation
5. Reporting
6. Releases
7. Distribution
Setup and Installation for Maven
Maven Website:
The Maven website is located here:
http://maven.apache.org
From this website you can download the latest version of Maven and follow the project in general.
You can download and install maven on windows, Linux and MAC OS platforms.
Note: Maven is Java based tool, so the very first requirement is to have JDK installed on your machine.
Download Maven archive:
Extract the Maven archive:
Extract the archive, to the directory you wish to install Maven 3.5.0. The sub directory Apache-maven-3.5.0 will be created from the archive.
Set Maven environment variables
Add M2_HOME, M2, MAVEN_OPTS to environment variables
Add Maven bin directory location to system path
Verify Maven installation
Maven help in project structure ,dependencies management,the reason behind is that maven repositories,maven talk to repositories and form the project structure.
Note: Maven get all its knowledge from maven repositories,Means how will be the project structure,what is the project type etc.
Contact Us
Visualpath IT Training institute
Flat 205, 2nd floor,Nilgiri block, Aditya Enclave
Ameerpet, Hyderabad - 16
Ph: 9704455959
Email: courseinfo@visualpath.in
www.visualpath.in
Comments
Post a Comment