Contact Free trial Login

Package a Mule Application

You can package your Mule applications using Mule Maven Plugin(command line) or Anypoint Studio. See Exporting Projects from Studio for details about this procedure.

Mule applications are packaged into a deployable JAR file that you can later deploy to a running Mule runtime engine. The package contains the application and all its dependencies whether those be JAR files required by the application or by its plugins.

Every Mule application has two descriptors. These descriptors define your Mule application’s dependencies:

  • A mule-artifact.json file.
    This file describes how your application is composed.

  • A pom.xml file.
    This file describes all the dependencies required by the package to work properly.

Compatibility

Mule 4 applications are compatible with the following Anypoint Studio and Mule Maven Plugin versions:

  • Anypoint Studio 7.x

  • Mule Maven Plugin 3.x

Prerequisites

Mule Application Structure Reference

At design time, your Mule application must have at least these three basic components:

Component Type Description

src

Folder

The source directory for your application’s productive source code and tests.
See a reference for this folder below.

pom.xml

Descriptor

The POM file of your Mule application.
This file describes all of your application’s required dependencies.

mule-artifact.json

Descriptor

The mule-artifact file of your Mule application.
This file describes how your Mule application is composed.

These three components are mandatory. If one of them is missing, the project cannot be packaged into a deployable JAR file.
Additionally, the packaging process does not consider any other directory or file in the root folder of your Mule application.

Source Directory Reference

The src directory has two main folders: main and test.
The plugin does not consider any other directory inside src when packaging the application.

src/main

src/main is the root folder for all the productive source code of the application.

Folder Folder Type Description

src/main/mule

source

The root folder of the Mule configuration files.
It can contain nested folders, in the way of Java packages.

This folder is mandatory.

src/main/resources

resource

It contains the application resources, such as XML, JSON, and properties files.
Jar files located here are loaded by the application classloader but as plain file resources.

The packaging process sends all files inside src/main/mule and src/main/resources to the root directory of your binary package.
Nested folders within src/main/mule are preserved as directories within the root directory of the binary package.

src/test

src/test is the root folder for all the test source code of the application.

Folder Folder Type Description

src/test/java

source

It’s the root folder of the test classes used to validate the custom Java code of the app.
It follows the conventions of any normal Java application.

src/test/munit

source

It contains the MUnit source code.
It can contain nested folders in the way of packages.

src/test/resources

resource

It contains resources, such as XML, JSON, and properties files.
This folder also contains files describing metadata being referenced in the mule-config.xml.

Package a Mule Application

From the command line in your project’s folder, execute the package goal:

mvn clean package

The plugin packages your application and creates the deployable JAR file into the target directory within your project’s folder.

Create an Application Package to Import into Anypoint Studio

To generate a JAR file that can be imported into Anypoint Studio, you must package your application using the -DattachMuleSources parameter to include source files and metadata that Studio requires to reimport the deployable file as an open Mule project into your workspace.

From the command line in your project’s folder, run:

mvn clean package -DattachMuleSources

The -DattachMuleSources parameter tells the plugin to add a mule-src folder inside the META-INF directory with an exact copy of your application structure at design time. This option also packages project modules and dependencies required to create a functioning Mule deployable archive file that can be deployed into a Mule runtime engine.

Create a Lightweight Package

You can skip bundling the actual modules and external dependencies required to run the Mule application in a Mule runtime engine, and create a lightweight package with only the source files and metadata required to import the JAR package back into Anypoint Studio.

From the command line in your project’s folder, run:

mvn clean package -DlightweightPackage

When you specify this parameter, the plugin creates a lightweight JAR file that does not include any dependencies declared in the Mule application’s pom.xml file. This JAR file cannot be deployed to a Mule runtime engine, it only offers a way to archive just the Mule application’s source files. The result of this Maven parameter is the same as unchecking Include project modules and dependencies when exporting the Mule application from Anypoint Studio.

Specify Multiple Parameters

You can also combine the parameters together to create a lightweight Mule application package that also includes the source files and metadata to import the package back into Anypoint Studio.

From the command line in your project’s folder, run:

mvn clean package -DattachMuleSources -DlightweightPackage

Exclude Files from the Application Package

When you package an application, you can exclude certain files or directories. Create a _muleExclude file at the project root directory and edit its content to set the exclusion rules.

Each line in a _muleExclude file specifies a rule that follows the glob pattern.

For example, consider the following _muleExclude file which contains two exclusion rules:

fileToBeExcluded.json
**/src/main/resources/local_directory
  • The first line indicates that all files named fileToBeExcluded.json, inside any directory, are excluded from the application package.

  • The second line indicates that only the directory named local_directory located under src/main/resources is excluded from the package.
    If **/src/main/resources/local_directory is replaced with local_directory then all directories named local_directory, inside the project, are excluded from the application package.

Was this article helpful?

πŸ’™ Thanks for your feedback!

Edit on GitHub