Contact Free trial Login

Maven Reference

This page summarizes reference information that helps you work when using Maven with Mule. Refer to Maven Support in Mule for an introduction and overview.

pom.xml File

<project root>/pom.xml

Project Object Model file that defines settings for a Maven project describing an application. It includes all settings necessary to build the application such as build plugin configurations. Note that the pom.xml exists on a per-project basis and is distributed along with a project.

settings.xml File

<system-wide Maven directory>/settings.xml
<user home directory>/.m2/settings.xml

Contains global settings for your Maven installation. Unlike a project’s pom.xml, it defines system-wide settings and is not distributed with a project, since it can contain confidential information such as authentication credentials.

The settings.xml file can reside in two locations:

  • In a system-wide settings folder:

    In this case, it is a global settings.xml file that defines the settings for all Maven installations on the system, regardless of user. For example:

    /etc/maven2/settings.xml
  • In a user-specific settings folder:

    In this case, it is a user settings.xml file that is relevant only for a specific user’s Maven installation. The default location is the .m2 directory in the user’s home directory:

    /home/joe/.m2/settings.xml

On a system with both global and user settings.xml files, the settings from both files become merged. In case there are duplicate settings, the user’s settings take precedence over the global settings.

Useful Commands

Locate the Maven binary and other files (Unix)

whereis mvn

Locate Maven files such as global configuration files (Unix)

locate maven

Obtain Maven version

mvn --version

This also provides other information such as the Java home directory, locale and processor architecture.

Obtain a List of Maven Commands and Options

mvn -h

Check the Manual Page for Maven (Unix)

man mvn

Create a Project

mvn archetype:generate -DgroupId=com.company.app -DartifactId=myapp -DarchetypeArtifactId=myarchetypeid -DinteractiveMode=false

Build a Project

mvn package

Clean a Project

mvn clean

Generate a Site

mvn site

Obtain a List of JAR Files Included in Your Artifact

mvn dependency:build-classpath

Obtain the Dependency Tree for Your Artifact

mvn dependency:tree

Deploying Mule Artifacts to a Central Maven Repository

Using a central repository can save users' time when building applications. To deploy to a central repository, you need to deploy the Mule POM files and JAR artifacts to the desired repository.

The deploy plugin is primarily used during the deploy phase, to add your artifacts to a remote repository for sharing with other developers and projects.

Deploying pom.xml

To deploy the pom.xml to a remote repository, use the following command:

mvn deploy:deploy-file
-DgroupId=${project.groupId}
-DartifactId=${project.artifactId}
-Dversion=${version}
-Dpackaging=pom
-Dfile=${localPom.canonicalPath}
-Durl=http://<your_repository_ip>/nexus/content/repositories/releases
-DrepositoryId=releases

For the -Durl parameter, replace <your_repository_ip> with the correct IP address. Also, the -DrepositoryId needs to match with the credentials defined in the settings.xml file.

Deploying the JAR files

To deploy a JAR file to a remote repository, use the following command:

mvn deploy:deploy-file
-DgroupId=${pomProps.groupId}
-DartifactId=${pomProps.artifactId}
-Dversion=${pomProps.version}
-Dpackaging=jar
-Dfile=${f.canonicalPath}
-DpomFile=${localPom.canonicalPath}
-Durl=http://${your_repository_ip}/nexus/content/repositories/releases
-DrepositoryId=releases

For the -Durl parameter, replace your_repository_ip with the correct IP address. Also, the -DrepositoryId needs to match with the credentials defined in the settings.xml file.

If you wish to both install the JAR files locally and deploy them remotely, you can keep both locations in the argument definition.