We would like to thank Sonali Shah for their contribution to this developer tutorial.
In this tutorial, we will walk through the process of publishing and using DataWeave libraries in Exchange and a Mule application. We will learn how to:
Organization ID- You can get the necessary information via the following:
Standard Date Formatsfolder):
To deploy your new DataWeave library to Exchange, you can follow the next 3 steps:
Let’s see them in detail.
From Visual Studio Code, in the
pom.xml file (located in the root folder of your DataWeave library), replace
org.mycompany from the
groupId field with your
Organization ID which we acquired in the Prerequisites.
distributionManagement and the
Exchange Repository details (inside the
ORGANIZATION_ID (in the
<url> tag) with your
Organization ID for both fields.
settings.xml file which can be found in the
If you don’t find this file in the
.m2 folder, you can create it manually. You can take this
settings.xml file as an example and just change the credentials.
Add the credentials you use to log in to Anypoint Platform to the
servers section. It should look similar to this:
1 2 3 4 5 6 7 <servers> <server> <id>exchange</id> <username>your-Anypoint-Platform-username</username> <password>your-Anypoint-Platform-password</password> </server> </servers>
Make sure the
<repository><id> in both the
repositories section in the
pom.xml matches the
<server><id> in the
.m2/settings.xml. For example,
<id>exchange</id> in all 3 places.
Run the following Maven command from the project’s root folder. Make sure it results in a BUILD SUCCESS. This command executes the unit tests, packages, installs and deploys the library.
1 mvn deploy
You can open a Terminal inside VSCode by selecting Terminal > New Terminal.
This will successfully create the library in Exchange.
Log in to Anypoint Platform and navigate to Exchange (you can access it through the menu button on the top left of the screen). Click on All types > DataWeave Libraries. Select the DataWeave library you just deployed (Standard Date Formats).
The library also contains the documentation related to the modules present in it. To modify the documentation of a specific function, you can modify it in the corresponding file (under
To use your new DataWeave library (deployed to Exchange) in a Mule application, you can follow the next 3 steps:
Let’s see them in detail.
From the DataWeave library published in Exchange, click on the Dependency Snippets button (or click on the three-dot button at the top-right of the screen if you’re on the old UI). Copy the Maven dependency. You can click on the Copy button.
Go to Anypoint Studio and create or open an existing Mule project.
If this is your first time opening Anypoint Studio, you can refer to this developer tutorial to understand the basics.
pom.xml file and paste the Maven dependency you just copied from Exchange. Make sure it’s inside the
<dependencies> tag and save your changes.
After you save, the jar should automatically be added to the Mule project, under Project Libraries.
We can access the
dateTimeConversion function from the
DateFormatConversion module by adding the following code into a Transform Message component in your Mule flow.
1 2 3 4 5 %dw 2.0 output application/json import dateTimeConversion from DateFormatConversion --- dateTimeConversion(now(), "dd/MM/yy")
Click on the Preview button to test if the code is working properly.
Do you have any questions about the code? You can compare your DataWeave library with ours to make sure everything was set up correctly.
This tutorial taught us how to publish and use DataWeave libraries in Exchange and Mule applications. We learned how to:
Remember you can go through the previous tutorial for a more detailed explanation of the DataWeave extension for Visual Studio Code and the best practices for creating a new DataWeave library project.
Continue your development journey with the rest of the tutorials to become a master in DataWeave.