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).
2. common-project:
This project will be used as a jar file in the main-project. Logger inside commonFlow will
print – inside common flow.
Step 2: Create jar file for common-project:
- Right click on the project and click Export
2. Click Mule, then select Anypoint Studio Project to Mule Deployable Archive (includes Studio metadata)
3. Export the Mule project by providing the jar file path. Select both checkboxes. Click Finish.
4. Jar file has been created: common.jar
Step 3: Go to main-project.
- Add common-project.jar as a jar file (dependency) in main-project. Right click on project -> Mule -> Add Maven Dependency.
2. Click Install in the bottom-right corner above the Finish button.
3. Browse to the common.jar file and click Install.
4. common-project.jar file will be added as a Maven dependency in main-project. Click OK.
Step 4
- 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.
2. Enter the file name common.xml which you want to import in your main-project from common-project. Click OK.
Step 5: Go to mainFlow and inside Flow reference connector -> select Flow name -> commonFlow.
Step 6: Run main-project.
- Right click on main-project -> Run As -> Mule Application.
2. main-project – deployed and running.
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.
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.