Nav

Getting Started with the Mule SDK for Java

Create your first Mule SDK project in just a few steps:

  • Install required software

  • Generate a project using Maven and explore it

  • Set up your IDE

  • Build the project you generated

  • Develop a connector or module

  • Run the connector or module in Anypoint Studio

The SDK provides a Maven plugin and a Maven archetype to create new projects. The archetype is a project template; use it to ensure your new project has a consistent structure, employs recommended practices, and contains a few elements for you to experiment with.

Install the Required Software

Install and verify that the following tools are working in your local environment:

  • Java Development Kit 8 (JDK 8) to compile and build your Java code.

  • Apache Maven, version 3.3.9 or higher, to manage your project’s build.

Generate a Project Using the Maven Plugin

Run the generate command to create an extension project based on the Maven archetype:

mvn org.mule.extensions:mule-extensions-archetype-maven-plugin:generate

You are prompted to provide required field values, then a new project is generated.

Explore the Generated Project

The generated project contains the basic Mule module structure with some basic classes, a dummy implementation, and two running tests that use the generated module.

Because this project is a Maven project, it contains a pom.xml file that contains all the information and configuration details used by Maven to perform the build. This generated POM file inherits from the module’s parent POM, which contains all the common configurations and defaults for all Mule module projects.


         
      
1
2
3
4
5
<parent>
  <groupId>org.mule.extensions</groupId>
  <artifactId>mule-modules-parent</artifactId>
  <version>1.1.0</version>
</parent>

Set Up Your IDE

For the SDK to work, you must pass the command line parameter -parameters to the Java compiler.

For Development in Studio or Eclipse

If you use Anypoint Studio or Eclipse:

  1. Right-click the project.

  2. Go to Java Compiler, and enable Store information about method parameters (usable via reflection).

600

For Development in IntelliJ

If you are using IntelliJ:

  1. Go to Preferences > Build, Execution, Deployment > Compiler > Java Compiler.

  2. Add -parameters in the Additional command line parameters section.

600

Build the Project

Once your project is generated, build it:

mvn clean install

This command compiles your project, runs the tests, and installs the project in your local Maven repository.

Develop Custom Module Code

Find the @Extension annotated class and examine module structure and the different elements that you can add to a module. Use these elements to modify a connector.

Add Your Connector to Studio

Once your connector is working, you can try it in Anypoint Studio.

Go to your Mule app pom.xml file and add the connector as a <dependency> with its groupId, artifactId, and version.

Example: Dependency

         
      
1
2
3
4
5
6
7
8
9
10
11
12
...
<dependencies>
  ...
  <dependency>
    <groupId>org.mule.connector</groupId>
    <artifactId>mule-connector</artifactId>
    <version>1.0.0</version>
    <classifier>mule-plugin</classifier>
  </dependency>
  ...
</dependencies>
...
Different features are available in different vesions of the SDK for Java. See Choosing the SDK version to pick the right version for your connector.