From BC$ MobileTV Wiki
Revision as of 20:07, 27 January 2022 by Bcmoney (Talk | contribs)

Jump to: navigation, search
Apache Software Foundation (ASF) logo
Apache Maven project

Maven is a dependency management system and build tool for rapid Java-based application development with rich features to streamline development and SCM. Maven is a Yiddish word which means "accumulator of knowledge". The Maven Project started out as an attempt to simplify build processes in a project with multiple Ant build scripts. It was proposed that a standard way to build projects, clearly define what a project consists of, easily publish project information and share JARs across several different projects would greatly simplify and lend efficiency and speed to the Java development process.




Although hardly a comprehensive list, these are the most common default lifecycle phases executed.

  • validate - validate the project is correct and all necessary information is available
  • compile - compile the source code of the project
  • test - test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
  • package - take the compiled code and package it in its distributable format, such as a JAR.
  • integration-test - process and deploy the package if necessary into an environment where integration tests can be run
  • verify - run any checks to verify the package is valid and meets quality criteria
  • install - install the package into the local repository, for use as a dependency in other projects locally
  • deploy - done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

There are two other Maven lifecycles of note beyond the default list above. They are

  • clean - cleans up artifacts created by prior builds
  • site - generates site documentation for this project



Build Commands

The following are some useful commands (don't forget to remove "mvn" before adding a command to a Run Configuration in your IDE of choice, the plugin will automatically call Maven).

Standard full clean & install (with complete maven repository building of dependencies via POM dependency list):

mvn clean install -PautoInstallPackage

Clean the target directory, build and explode out a WAR file, run it in an embedded Jetty server (should be configured properly in pom.xml).

mvn clean war:exploded jetty:run -e

Run unit tests:

mvn test

Package a runnable JAR, WAR or EAR:

mvn package

Build a new snapshot and release:

mvn -U deploy

An interesting thing to note is that phases and goals may be executed in sequence:

mvn clean dependency:copy-dependencies package



Search for JARs in your local Maven repository (local cache):

file ~/.m2/repository/org/jsoup/jsoup/1.10.3/jsoup-1.10.3.jar

Given a specific JAR, search contents to find a specific class (for debugging any "ClassNotFoundException" and similar issues):

jar -tf ~/.m2/repository/org/jsoup/jsoup/1.10.3/jsoup-1.10.3.jar | grep org/jsoup/parser/Parser


[6] [7]


Build Profiles are used to set one or more distinct sets of properties and/or build commands (for instance Local Dev .vs. Test Environment .vs. Prod Environment settings).

[8] [9]

[10] [11]


In Maven, the Project Object Model (POM) is the term given to the XML-based definition of a project (similar to DOAP), which focuses on providing a listing of Dependencies (libraries, supporting tools, etc), where to download or obtain those Dependencies, and how to use those dependencies together with the code contained in the software project in order to successfully perform a Build. It also provides a linkage to Defect Management (aka. Issue Management) & Testing tools. The following is an empty template for the syntax of the POM file.

 <project xmlns=""

  <!-- The Basics -->

  <!-- Build Settings -->

  <!-- Additional Project Information -->

   <!-- Environment Settings -->

Dependency Tree

You can view your dependency tree by running the following from command-line:

mvn dependency:tree

For larger apps or heavier more complex Maven configurations, you may want to pipe the output to a file to open in a text editor as it could be hard to read from a console/terminal:

mvn dependency:tree -Dverbose >> C:/APPS/dependencies.txt

Find Out-of-Date Plugins

You can list Maven plugins that are outdated using the following command:

mvn versions:display-plugin-updates
Find Out-of-Date Dependencies

You can list libraries that are both out-of-date (it will also differentiate those that "should" be able to be upgraded safely, based on Semantic Versioning) using the following command:

mvn versions:display-dependency-updates









[13] [14]


Assembly Plugin for Maven enables developers to combine project output into a single distributable archive that also contains dependencies, modules, site documentation, and other files.

[15] [16] [17]

Continuous Integration

Continuous Integration

Static Code Analysis

[18] [19] [20] [21] [22] [23] [24]






Config processor


Exec (command-line)


Language Extensions

While just about any program can be run remotely in a cloud environment via the CloudTools plugin, or by calling a local program from the command-line via the Exec plugin, there are still instances when you want to work more closely with a given programming language's specific tools such as compilers, testing suites, IDEs, etc. You can accomplish this by using one of the many Language-specific Maven extensions.








[35] [36] [37]


[49][50] [51] [52]


[67] [68] [69]

[70] [71] [72] [73]

[74] [75] [76] [77] [78] [79] [80] [81] [82] [83]

External Links


  1. Setting Up Your Project to Use the Build Lifecycle:
  2. Maven in 5 Minutes:
  3. Tutorial -- Build a JAR file with Maven in 5 minutes:
  4. :
  5. Maven build debug in Eclipse:
  6. Maven separate Unit Test and Integration Tests:
  7. What is the difference between the Maven Surefire and Maven Failsafe plugins?:
  8. Guide to Maven Profiles:
  9. Setting default values for custom Maven 2 properties:
  10. Active by default Maven profile and other profiles:
  11. How to keep Maven profiles which are activeByDefault active even if another profile gets activated?:
  12. Read FILE properties via maven-properties plugin:
  13. mvn exec plugin -- Usage: (valid
  14. mvn exec plugin -- Changing the classpath scope when running Java programs:
  15. Apache Mache Assembly Plugin - usage:
  16. Apache Mache Assembly Plugin - POM.xml config examples:
  17. assembly:single - assemble an application bundle or distribution from an assembly descriptor.:
  18. Maven -- Unable to locate Source XRef to link to:
  19. SCA reporting with "maven-jxr-plugin": | DOCS - JXR plugin usage
  20. Better site documentation with Maven (Part V) - static code analysis with PMD:
  21. OpenHAB's excellent example of a Static Code Analysis Tools is a Maven plugin that executes the Maven plugins for SpotBugs, Checkstyle and PMD and generates a merged .html report:
  22. Maven PMD - Analyzing JSP Code:
  23. Maven PMD - Analyzing JavaScript Code:
  24. The Maven build task now supports PMD analysis out of the box:
  25. Maven – PMD example:
  26. Analyzing JavaScript Code:
  27. Introduction to FindBugs:
  28. FindBugs Maven Plugin tutorial:
  29. Native C/C++ Maven Plugin (usage):
  30. How do I use Maven through a proxy?:
  31. Maven -- Versions plugin - Changing the project version:
  32. Maven -- Versions plugin - Advancing dependency versions:
  33. Maven -- Versions plugin - Replacing -SNAPSHOT versions with their corresponding releases:
  34. Robustly enforcing a minimum Maven version for your project:
  35. Creating Profile Specific Configuration Files With Maven:
  36. Build profiles -- (environment-specific) properties filtering example "pom.xml":
  37. Maven - How do I activate a profile from command line?:
  38. Where is Maven' settings.xml located on Mac os?:
  39. How to Install Maven on macOS using Homebrew:
  40. Install Maven on Mac:
  41. How to install Maven on Mac OSX:
  42. How to Install Maven on Mac OS:
  43. How to convert a Maven pom.xml into an Ivy ivy.xml file :
  44. Convert Maven POM dependencies to ivy.xml file:
  45. m2eclipse wont download maven artifacts:
  46. Unable to download jars using M2Eclipse (0.10.0, using Maven 3):
  47. Code Sharing (amongst several team members)? Use Maven:
  48. Maven & Jenkins with Selenium: Complete Tutorial:
  49. NetBeans Platform Quick Start Using Maven:
  50. Maven 3 support in NetBeans IDE 7.0+:
  51. Integrating Maven with IBM Rational Application Developer (RAD) 7.5:
  52. Hello World Maven on the NetBeans RCP:
  53. NetBeans Platform Maven Command Line Tutorial:
  54. NetBeans Platform Quick Start Using Maven:
  55. Creating an Enterprise Application Using Maven
  56. NB - Convert a project to Maven?:
  57. Converting a Netbeans project to a Maven enabled project:
  58. How to Create Web Application using Maven and Netbeans:
  59. Add JDBC in Netbeans Maven Project:
  60. NetBeanws -- Testing a Maven Enterprise Application:
  61. Maven – How to skip unit test:
  62. Difference between -Dmaven.test.skip=true and -DskipTests in Maven:
  63. Maven skip tests (explained):
  64. maven profiles - load based on environment :
  65. Best practices for copying files with Maven:
  66. Maven2 -- Missing artifact but JARs are in place:
  67. Maven build script for replacement of text in web.xml (and others):
  68. Using Maven Replacer Plugin to replace strings from a properties file:
  69. Maven replacer -- replacement value containing dollar signs:
  70. Understanding Maven Version Numbers:
  71. Release vs. Snapshot repositories:
  72. How to Use Snapshot of Library in Maven Project:
  73. Maven Snapshot Repository vs Release Repository:
  74. javax.annotation,version -- Cannot be resolved #229:
  75. javax.annotation,version -- Cannot be resolved #270 :
  76. javax.annotation classes and Java 11 JDK:
  77. Can't find @Nullable inside javax.annotation.*:
  78. Maven central -- javax.annotation:
  79. Maven central --
  80. Maven repository -- javax.annotation:
  81. OSGi import of javax.annotation and javax.annotation.meta is broken in 1.14.2 #1616:
  82. JSoup -- bug fix to remove javax.annotation.meta specific version transient dependency:
  83. Where is javax.annotation:
  84. m2e lifecycle-mapping not found:
  85. Getting parent directory of ${basedir} from maven:
  86. What is the purpose of mvnw and mvnw.cmd files?:

See Also

Ant | Java | CI | Testing | SCM | Semantic Versioning