Close this search box.
Cloning MuleSoft Projects To Maximize Efficiency

Cloning MuleSoft Projects to Maximize Efficiency

When considering reuse, people all too often consider only the number of distinct consumers utilizing their APIs or integration services. However, there are many additional constructs to consider when driving reusability for integration assets.

What is reusability?

Reusability is when an integration object or process is built and then used several times after its initial use — either by the individual that created it or across teams/organizations. Reusability is a non-functional requirement that every development team strives for.

A great way to do this is to import one MuleSoft project as a jar file into another MuleSoft project. Below are the steps to do this.

Step 1: Create 2 mule projects: main-project and common-project.

1. Inside main-project:

Main logger will print – inside main flow (when the application is up & running).

inside main flow

2. common-project:

This project will be used as a jar file in the main-project. Logger inside commonFlow will

print – inside common flow.

Inside common flow

Step 2: Create jar file for common-project:

  1. Right click on the project and click Export

create jar file

2. Click Mule, then select Anypoint Studio Project to Mule Deployable Archive (includes Studio metadata)

Anypoint studio

3. Export the Mule project by providing the jar file path. Select both checkboxes. Click Finish.

export mulesoft project

4. Jar file has been created: common.jar

Jar file created

Step 3: Go to main-project.

  1. Add common-project.jar as a jar file (dependency) in main-project. Right click on project -> Mule -> Add Maven Dependency.

add Maven Dependency

2. Click Install in the bottom-right corner above the Finish button.

pick a maven dependency

3. Browse to the common.jar file and click Install.

intall common jar file

4. common-project.jar file will be added as a Maven dependency in main-project. Click OK.

common jar added

Step 4

  1. Go to main.xml in main-project.
    Click Global elements, then click Create and type import in the Filter field. Select Import and click OK.

choose global type

2. Enter the file name common.xml which you want to import in your main-project from common-project. Click OK.

Global element properties

Step 5: Go to mainFlow and inside Flow reference connector -> select Flow name -> commonFlow.

flow reference connector

Step 6: Run main-project.

  1. Right click on main-project -> Run As -> Mule Application.

run as mule application

2. main-project – deployed and running.

Main project deploy and run

3. See console to check the logger from commonFlow.

This will print “inside common flow”, which is getting referred from the main project to call commonFlow from common-project via the Flow Reference connector.

check logger from common flow

That’s all there is to it! We have successfully imported common-project as a jar file in main-project. Thus, the existing code can be reused and you’ve saved quite a bit of time!

Interested to learn more? Take a look at how we can help you get the most out of your data and investment in MuleSoft.