Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Apache Maven
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Design == === Project Object Model === A Project Object Model (POM) <ref>[https://maven.apache.org/pom.html POM Reference] </ref> provides all the configuration for a single project. General configuration covers the project's name, its owner and its dependencies on other projects. One can also configure individual phases of the build process, which are implemented as [[plug-in (computing)|plugin]]s. For example, one can configure the compiler-plugin to use Java version 1.5 for compilation, or specify packaging the project even if some unit tests fail. Larger projects should be divided into several modules, or sub-projects, each with its own POM. One can then write a root POM through which one can compile all the modules with a single command. POMs can also inherit configuration from other POMs. All POMs inherit from the Super POM<ref>[https://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Super_POM Super POM] </ref> by default. The Super POM provides default configuration, such as default source directories, default plugins, and so on. === Plug-ins === Most of Maven's functionality is in [[plug-in (computing)|plug-in]]s. A plugin provides a set of goals that can be executed using the command <code>mvn [plugin-name]:[goal-name]</code>. For example, a Java project can be compiled with the compiler-plugin's compile-goal<ref>{{cite web|url=https://maven.apache.org/plugins/maven-compiler-plugin/|title=Apache Maven Compiler Plugin β Introduction|first=Edwin|last=Punzalan}}</ref> by running <code>mvn compiler:compile</code>. There are Maven plugins for building, testing, source control management, running a web server, generating [[Eclipse (software)|Eclipse]] project files, and much more.<ref>{{cite web|url=https://maven.apache.org/plugins/index.html|title=Maven β Available Plugins|first=Brett Porter Jason van Zyl Dennis Lundberg Olivier Lamy Benson Margulies Karl-Heinz|last=Marbaise}}</ref> Plugins are introduced and configured in a <plugins>-section of a <code>pom.xml</code> file. Some basic plugins are included in every project by default, and they have sensible default settings. However, it would be cumbersome if the archetypal build sequence of building, testing and packaging a software project required running each respective goal manually: * <code>mvn compiler:compile</code> * <code>mvn surefire:test</code> * <code>mvn jar:jar</code> Maven's lifecycle concept handles this issue. Plugins are the primary way to extend Maven. Developing a Maven plugin can be done by extending the org.apache.maven.plugin.AbstractMojo class. Example code and explanation for a Maven plugin to create a cloud-based virtual machine running an application server is given in the article ''Automate development and management of cloud virtual machines''.<ref>{{Cite journal| last=Amies| first=Alex|author2=Zou P X |author3=Wang Yi S | title=Automate development and management of cloud virtual machines|journal=IBM DeveloperWorks|publisher=IBM|date=29 Oct 2011| url=http://www.ibm.com/developerworks/cloud/library/cl-automatecloud/index.html}}</ref> === Build lifecycles === The build lifecycle is a list of named ''phases'' that can be used to give order to goal execution. One of Maven's three standard lifecycles is the ''default lifecycle'', which includes the following phases, performed in the order listed:<ref>{{cite web|url=https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference|title=Maven β Introduction to the Build Lifecycle|first=Brett|last=Porter}}</ref> * validate * generate-sources * process-sources * generate-resources * process-resources * compile * process-test-sources * process-test-resources * test-compile * test * package * install * deploy Goals provided by plugins can be associated with different phases of the lifecycle. For example, by default, the goal <code>compiler:compile</code> is associated with the <code>compile</code> phase, while the goal <code>surefire:test</code> is associated with the <code>test</code> phase. When the <code>mvn test</code> command is executed, Maven runs all goals associated with each of the phases up to and including the <code>test</code> phase. In such a case, Maven runs the <code>resources:resources</code> goal associated with the <code>process-resources</code> phase, then <code>compiler:compile</code>, and so on until it finally runs the <code>surefire:test</code> goal. Maven also has standard phases for cleaning the project and for generating a project site. If cleaning were part of the default lifecycle, the project would be cleaned every time it was built. This is clearly undesirable, so cleaning has been given its own lifecycle. Standard lifecycles enable users new to a project the ability to accurately build, test and install every Maven project by issuing the single command <code>mvn install</code>. By default, Maven packages the POM file in generated JAR and WAR files. Tools like diet4j<ref>{{cite web|url=http://diet4j.org/|title=diet4j - put Java JARs on a diet, and load maven modules as needed}}</ref> can use this information to recursively resolve and run Maven modules at run-time without requiring an "uber"-jar that contains all project code. === Dependencies === A central feature in Maven is [[Dependency (project management)|dependency management]]. Maven's dependency-handling mechanism is organized around a coordinate system identifying individual artifacts such as software libraries or modules. The POM example above references the JUnit coordinates as a direct dependency of the project. A project that needs, say, the [[Hibernate (Java)|Hibernate]] library simply has to declare Hibernate's project coordinates in its POM. Maven will automatically download the dependency and the dependencies that Hibernate itself needs (called [[Transitive dependency|transitive dependencies]]) and store them in the user's local repository. Maven 2 [https://search.maven.org/ Central Repository]<ref name="maven2repo"/> is used by default to search for libraries, but one can configure the repositories to be used (e.g., company-private repositories) within the POM. The fundamental difference between Maven and Ant is that Maven's design regards all projects as having a certain structure and a set of supported task work-flows (e.g., getting resources from source control, compiling the project, unit testing, etc.). While most software projects in effect support these operations and actually do have a well-defined structure, Maven requires that this structure and the operation implementation details be defined in the POM file. Thus, Maven [[Convention over configuration|relies on a convention]] on how to define projects and on the list of work-flows that are generally supported in all projects.<ref>{{cite web|title=Maven: The Complete Reference |url=http://www.sonatype.com/books/mvnref-book/reference/installation-sect-compare-ant-maven.html |publisher=Sonatype |access-date=11 April 2013 |url-status=dead |archive-url=https://web.archive.org/web/20130421060027/http://www.sonatype.com/books/mvnref-book/reference/installation-sect-compare-ant-maven.html |archive-date=21 April 2013 }}</ref> There are search engines such as The Central Repository Search Engine,<ref>[https://search.maven.org/ The Central Repository Search Engine]</ref> which can be used to find out coordinates for different open-source libraries and frameworks. Projects developed on a single machine can depend on each other through the local repository. The local repository is a simple folder structure that acts both as a cache for downloaded dependencies and as a centralized storage place for locally built artifacts. The Maven command <code>mvn install</code> builds a project and places its binaries in the local repository. Then, other projects can utilize this project by specifying its coordinates in their POMs.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)