Nav
You are viewing an older version of this section. Click here to navigate to the latest version.

Maven Reference

This page summarizes reference information that is helpful for working with Maven and Mule. Refer to Using Maven with Mule for an introduction and overview.

Populating the Maven Repositories From the Command Line

You don’t usually need to do this, as it occurs automatically when creating a Maven Mule project. In case something doesn’t work as expected, you have the option of doing it manually.

To include Mule libraries as dependencies of your project, you must populate your Maven repository with these. To do this manually, you can run the populate_m2_repo script in $MULE_HOME/bin from the command line.

On Unix:


         
      
1
$MULE_HOME/bin/populate_m2_repo

On Windows:


         
      
1
%MULE_HOME%\bin\populate_m2_repo.cmd

These scripts call $MULE_HOME/bin/populate_m2_repo.groovy which you can modify.

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.

Deploying pom.xml

In your Mule installation, locate the file <MULE_HOME>/bin/populate_m2_repo.groovy and open it for editing. Locate the following line:


          
       
1
2
3
4
mvn(["install:install-file",
 "-DgroupId=${project.groupId}", "-DartifactId=${project.artifactId}",
"-Dversion=${version}", "-Dpackaging=pom",
"-Dfile=${localPom.canonicalPath}"])

Modifiy the line as shown.


          
       
1
2
3
4
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.

Deploying the JARs

In the  <MULE_HOME>/bin/populate_m2_repo.groovy file, locate the second // Install pom via maven comment. Immediately below this line is the argument definition, which reads as shown below.


          
       
1
def args = ["install:install-file", "-DgroupId=${pomProps.groupId}", "-DartifactId=${pomProps.artifactId}", "-Dversion=${pomProps.version}", "-Dpackaging=jar", "-Dfile=${f.canonicalPath}", "-DpomFile=${localPom.canonicalPath}"]

Modify this line as shown.


          
       
1
2
3
4
5
def args = ["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.

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

Referencing MuleSoft’s Enterprise Repositories

Checking JARs Included in a Project

Maven can automatically include dependencies into your project. It is possible that, when attempting to test the project outside of Maven, you may find that you need to explicitly define these dependencies for the project to work. For example, if you create a project with Studio and Maven and build it using another tool such as Apache Ant, you need to ensure that all dependencies required for the project are included in your Ant config.

To obtain a list of dependencies included in your project, run the following command:


         
      
1
mvn dependency:build-classpath

Files

pom.xml


          
       
1
<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.

See the https://maven.apache.org/pom.html[POM Reference] at the Apache Maven online documentation for details.

settings.xml


          
       
1
2
<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 may reside in two locations: in a system-wide settings folder, and in a user-specific settings folder. In the first case, it is a global settings file which defines the settings for all Maven installations on the system, regardless of user. For example:


          
       
1
/etc/maven2/settings.xml

In the second, per-user case, the file is a user settings file only relevant for a specific user’s Maven installation. In this case, the default location is the .m2 directory in the user’s home directory:


          
       
1
/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 of duplicate settings, the user’s settings take precedence over the global settings.

For a complete reference for this file, see Settings Reference on the Apache Maven online documentation.

Useful Commands

Locate the Maven binary and other files (Unix)


          
       
1
whereis mvn

Locate Maven files such as global configuration files (Unix)


          
       
1
locate maven

Obtain Maven version


          
       
1
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


          
       
1
mvn -h

Check the manual page for Maven (Unix)


          
       
1
man mvn

Create a project


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

Build a project


          
       
1
mvn package

Clean a project


          
       
1
mvn clean

Generate a Site


          
       
1
mvn site

Obtain a list of jars included in your artifact


          
       
1
mvn dependency:build-classpath

Obtain the dependency tree for your artifact


          
       
1
mvn dependency:tree