Maven Notes

Topics: Apache Ant, Apache Maven, Build automation Pages: 7 (875 words) Published: October 5, 2014
Maven for building Java applications - Tutorial

1 of 7

http://www.vogella.com/tutorials/ApacheMaven/article.html

Version 1.7
Copyright © 2013 Lars Vogel
02.07.2014

This tutorial describes the usage of Maven for building Java applications.

Table of Contents

Apache Maven is a build tool to support the developer at the whole process of a software project. Maven allows the developer to automate the process of the creation of the initial folder structure, performing the compilation and testing and the packaging and deployment of the final product. It is implemented in Java which makes it platform-independent. Java is also the best work environment for Maven. Apache Maven can be used in environments where common build tools like GNU Make or Apache Ant were used. The key features of Maven are:

Convention over configuration: Maven tries to avoid as much configuration as possible, by choosing real world default values and supplying project templates (archtypes) Dependency management: - it is possible to define dependencies to other projects. During the build, the tool resolves the dependencies and if needed it also builds the dependent projects Central repository: - project dependencies can be loaded from the local file system, from the Internet or public repositories. The company behind the Maven project also provides a central repository called Maven Central.

13-09-2014 12:49

Maven for building Java applications - Tutorial

2 of 7

http://www.vogella.com/tutorials/ApacheMaven/article.html

Maven supports project scaffolding, i.e. template generation, for different project types, so called archtype. The goal of this scaffolding is to allow a fast start into the Maven world and supports a "standardized" folder structure of software projects.

You can create a project by executing the generate goal on the archetype plugin : $mvn starts the generate process in the interactive mode and asks you for several settings.

archetype:generate

. This

The configuration of a Maven project is done via a Project Object Model, which is represented by the pom.xml file. By default, this is the only configuration file required for the build process. Every build follows a specified life cycle. Maven comes with a default life cycle that includes the most common build phases like compiling, testing and packaging. All phases are made up of plugin goals. Plugin goals are tasks which are more specific than phases. So a phase can be defined to run more than one plugin goal.

The result of a build is called artifact. An artifact, for example, can be a executable or an archive of documents.

For Linux most distributions include Maven into their main repositories. On Ubuntu you can use the following command on the command line to install it. sudo apt-get install mvn

For a manual installation you can download Maven from the following URL Maven Download page. Extract the download to a selected folder on your computer and add the M2_HOME environment pointing to this directory. Add M2_HOME/bin to your path variable.

To see the installation details for other system, follow the guide from the Maven project site.

To validate that Maven was correctly installed, open a console and use the following command: mvn

-version.

You should receive as output feedback which version of Maven you have installed.

Maven is a command line tool which will be started on the terminal. To run a build with Maven, you just have to point your command line to the folder which includes the pom.xml file and run the command mvn install.

With this single line, the maven lifecycle will be started. So the configuration from the pom.xml will be loaded and the dependencies will be resolved. After this, Maven tries to load the lastest version of the depended artifacts from the central repository into a local repository, which is placed as .m2/repository in the users home directory. As part of the lifecycle, the build tool compiles the...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Note Taking Methods Essay
  • My Project on Samsung Note 2 Essay
  • Essay about Taking Notes in College
  • Journal on Note Taking Essay
  • Note taking Essay
  • Course Project ; Notes to the Financial Statement Essay
  • The Lost Art of Thank-You Notes- Randy Pausch Essay
  • Quotation and Research Notes Essay

Become a StudyMode Member

Sign Up - It's Free