What is a POM on maven?

13,882

Solution 1

The pom.xml file is the core of a project's configuration in Maven. It is a single configuration file that contains the majority of information required to build a project in just the way you want. The POM is huge and can be daunting in its complexity, but it is not necessary to understand all of the intricacies just yet to use it effectively.

Below is just a simple example:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>Maven Quick Start Archetype</name>
  <url>http://maven.apache.org</url>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.8.2</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

To build the dependencies that you specified in pom.xml file execute: mvn clean package After a successfull mvn package you will see something like below:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Tue Jul 23 (Time..)
[INFO] Final Memory: 3M/6M
[INFO] -----------------------------

the above command will download all the dependencies to your home directory /home/user/.m2/..

  1. Have a look on this How to create a maven project
  2. Also have a look to Maven in 5 min

Solution 2

A pom.xml file describes how to build a project. It can be considered the Java version of a Makefile in C/C++ or setup.py in Python. Are you following a specific example?

Share:
13,882
Uder Moreira
Author by

Uder Moreira

NooB.

Updated on June 13, 2022

Comments

  • Uder Moreira
    Uder Moreira almost 2 years

    I'm trying to follow the get started manual of maven, but I receive this error

    c:\Ambiente\workspace>mvn archetype:generate \ -DarchetypeGroupId=org.apache.maven.archety
    pes \ -DgroupId=com.mycompany.app \  -DartifactId=my-app -X
    Apache Maven 3.1.0 (893ca28a1da9d5f51ac03827af98bb730128f9f2; 2013-06-27 23:15:32-0300)
    Maven home: C:\Ambiente\apache-maven-3.1.0
    Java version: 1.7.0_25, vendor: Oracle Corporation
    Java home: C:\Program Files\Java\jdk1.7.0_25\jre
    Default locale: pt_BR, platform encoding: Cp1252
    OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
    [INFO] Error stacktraces are turned on.
    [DEBUG] Reading global settings from C:\Ambiente\apache-maven-3.1.0\conf\settings.xml
    [DEBUG] Reading user settings from C:\Users\t316360\.m2\settings.xml
    [DEBUG] Using local repository at C:\Users\t316360\.m2\repository
    [DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10.0 for C:\Users\t3163
    60\.m2\repository
    [INFO] Scanning for projects...
    [DEBUG] Extension realms for project org.apache.maven:standalone-pom:pom:1: (none)
    [DEBUG] Looking up lifecyle mappings for packaging pom from ClassRealm[plexus.core, parent
    : null]
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 0.078s
    [INFO] Finished at: Mon Jul 22 17:23:03 BRT 2013
    [INFO] Final Memory: 11M/247M
    [INFO] ------------------------------------------------------------------------
    [ERROR] The goal you specified requires a project to execute but there is no POM in this d
    irectory (c:\Ambiente\workspace). Please verify you invoked Maven from the correct directo
    ry. -> [Help 1]
    org.apache.maven.lifecycle.MissingProjectException: The goal you specified requires a proj
    ect to execute but there is no POM in this directory (c:\Ambiente\workspace). Please verif
    y you invoked Maven from the correct directory.
    

    what is POM and what do I suppose to do to have this file?

  • samsquanch
    samsquanch almost 11 years
    Ah I see. That command will generate a vanilla version of a pom.xml for you. The trouble is the backslashes in the command you typed. Backslashes are supposed to denote a command that takes multiple lines. Remove the backslashes and try running it all on one line.
  • ocrampico
    ocrampico about 7 years
    i got the same problem why i used the command provided on gettin-started but correct generate command are, as @tokhi says above, in Maven in 5 min (link above)