Contact Us 1-800-596-4880

Creating Example Archetypes

Mule provides Maven archetypes that you can use as code templates for your Mule projects. These templates include a set of implementation notes and "to-do" pointers that help you get started quickly. The Mule example archetype helps you generate a tailored boilerplate example project in seconds.

Follow the instructions below to create template files for a new Mule example, including all the necessary Java boilerplate and detailed implementation instructions in comments.

Configuring Maven

Add the following to the settings.xml file (usually in your Maven conf or $HOME/.m2 directory) so that Maven allows you to execute Mule plug-ins.

<settings>
    <pluginGroups>
        <pluginGroup>org.mule.tools</pluginGroup>
    </pluginGroups>
    ...
</settings>

Using the Archetype

First, open a command shell and change to the directory where you want to create your example project.

cd yourDir

Next, execute the archetype and generate the code. If this is your first time running this command, Maven downloads the archetype for you.

mvn mule-example-archetype:create -DartifactId=xxx -DmuleVersion=2.2.0

At minimum, you pass in two system parameters:

  • artifactId: The short name for the project (such as 'myExample'). This must be a single word in lower case with no spaces, periods, hyphens, etc.

  • muleVersion: The version of the Mule project archetype you want to use. This is the default Mule version used for the generated artifact.

    Running the archetype

    By default, Maven uses the latest available version of the archetype. This can cause problems if you want to create an example for an earlier version of Mule. In this case, run the mule-example-archetype specifying the full version of the plug-in like this:

    mvn org.mule.tools:mule-example-archetype:3.5.0:create ...

    artifactId

    As of Mule 2.2 the artifactId can contain characters such as underscore or hyphen. However, the plug-in will convert the name into a usable form suitable for Java. For example, if the argument is specified as -DartifactId=My#Awesome-Mule_Project, the project is created in a directory of that name, but the project name will be MyAwesomeMuleProject and the package name is .myawesomemuleproject.

The plug-in asks various questions (described below) and then generates the files. You can also use this plug-in without user prompts by entering all the arguments at the command line.

After you answer all the questions, the archetype creates a directory using the example project name you specified that includes a POM file for building with Maven, a Mule configuration file (conf/mule-config.xml) that includes the namespaces for the transports and modules you specified and has placeholder elements for creating your first flow and a package.html file under src/main/java using the package path you specified. The archetype also creates files in the dist folder that you need to distribute to users, including a readme file and a batch file for running the example. Lastly, the archetype creates template files under src/test to help you get started creating a unit test for the example. A new MULE-README.txt file creates in the root of your project explaining what files were created.

Example Console Output

The plug-in prompts you to answer several questions about the example you are creating. These may vary according to the options you select. An example of the output is shown below.

In the example that follows, MuleForge hosting no longer exists. Enter n at the MuleForge prompt.
[INFO] description:
********************************************************************************

Provide a description of what the example does:

[default:]
********************************************************************************

[INFO] muleVersion:
********************************************************************************

Which version of Mule is this example targeted at?

[default: 2.2.0]
********************************************************************************

[INFO] forgeProject:
********************************************************************************

Will This project be hosted on MuleForge? [y] or [n]

[default: y]
********************************************************************************

[INFO] transports:
********************************************************************************

Which Mule transports do you want to include in this project?
(options: axis,cxf,ejb,file,ftp,http,https,imap,imaps,jdbc,
          jetty,jms,multicast,pop3,pop3s,quartz,rmi,servlet,smtp,
          smtps,servlet,ssl,tls,stdio,tcp,udp,vm,xmpp):

[default: cxf,file,http,jdbc,jms,stdio,vm]

********************************************************************************

[INFO] modules:
********************************************************************************

Which Mule modules do you want to include in this project?

(options: builders,client,jaas,jbossts,management,ognl,pgp,scripting,
          spring-extras,sxc,xml):

[default: client,management,scripting,sxc,xml]

********************************************************************************

OGNL is deprecated in Mule 3.6 and will be removed in Mule 4.0.

The Questions Explained

Provide a description of what the example does:

You should provide an accurate description of the example with any high-level details of what you can or cannot do with it. This text is used where a description of the example is required.

Which version of Mule is this example targeted at?

The version of Mule you want to use for your example. This defaults to the archetype version passed in on the command line.

Which Mule transports do you want to include in this project?

A comma-separated list of the transports you plan to use in this example (such as HTTP and VM). This adds the namespaces for those transports to the configuration file.

Which Mule modules do you want to include in this project?

A comma-separated list of the modules you plan to use in this example (such as XML and Scripting). This adds the namespaces for those modules to the configuration file.

Command Line Options

By default, this plug-in runs in interactive mode, but it’s possible to run it in 'silent' mode by using the following option:

-DinteractiveMode=false

The following options can be passed in:

Name Example Default Value

groupId

-DgroupId=org.mule.examplexxx

org.mule.example.<artifactId>

forgeProject

-DforgeProject=n

y

packagePath

-DpackagePath=org/mule/example

none

transports

-Dtransports=http,vm

cxf,file,http,jdbc,jms,stdio,vm

muleVersion

-DmuleVersion2.2.0

none

packageName

-DpackageName=myPkg

none

description

-Ddescription="some text"

none

modules

-Dmodules=xml,scripting

client,management,scripting,xml

basedir

-Dbasedir=/projects/mule/tools

<current dir>

package

-Dpackage=org/mule/example/myPkg

none

artifactId

-DartifactId=myMuleExample

mule-application-<artifactId>

version

-Dversion=2.2-SNAPSHOT

<muleVersion>

You need to use double quotes when passing values with spaces in between.
For example: -Ddescription="some text".