Using Mulesoft Exchange for storing custom JAR files

Verma Varun
3 min readAug 28, 2020

There are so many ways of hosting custom JAR files and importing them for your projects. You could use a Nexus server, store them in GitHub or even install them locally on all machines. But in a production environment, you may not have access to the build server to go and install custom JAR files. Adding them to your Nexus server in that case (if available) might seem like a good idea, but it comes with a drawback that every developer will have to setup a local Nexus server to keep the build process in sync with the production setup.

However, there is an easy alternative that works well with Mulesoft and Maven. The solution is to store the custom JAR files into the Exchange repository. The exchange repository comes with your own Organization ID where you could host private JAR files that may only be accessible using your account credentials. The account credentials can be saved in your ~/.m2/settings.xml file and likewise on the build server.

Here are the steps to get your custom JAR into Anypoint Exchange and use it across all environments — [local/dev/beta/prod] without any connectivity issues.

  1. Navigate to Anypoint Exchange and click on “Publish new asset

2. Enter the asset Name, select Asset types as “Custom” and upload the JAR file from your desktop

3. The asset will be published to the exchange using a similar URL that would contain the Org ID and the asset name: https://anypoint.mulesoft.com/exchange/758f3006–1b00–465d-81c8-dac355598eb3/secure-properties-tool/. You would require this Org ID later.

4. Add the following repository to your list of repositories in the POM file:

<repository>  
<id>anypoint-exchange</id>
<name>Anypoint Exchange</name>
<url>https://maven.anypoint.mulesoft.com/api/v2/maven</url>
<layout>default</layout>
</repository>

5. You can encrypt the password using the code below to save the encrypted password in the settings.xml file.

> mvn -ep “UNENCRYPTED_PASSWORD”

Add the following snippet to your ~/.m2/settings.xml file. Make sure that the server <id> in the settings.xml matches the repository <id> you specified in the repositories in the POM file.

<server>
<id>anypoint-exchange</id>
<username>{your-anypoint-username}</username>
<password>{your-encrypted-anypoint-password}</password>
</server>

6. Add the dependency to your POM file under dependencies, in the project where you are using this dependency. Notice that the Group ID is the same as the Org ID that you got from the asset URL from the exchange described above. And the classifier is set to “custom” as this is a custom artifact.

<dependency>
<groupId>758f3006–1b00–465d-81c8-dac355598eb3</groupId>
<artifactId>secure-properties-tool</artifactId>
<version>1.0.0</version>
<classifier>custom</classifier>
</dependency>

7. After adding the dependency, you need to share it using the mule-maven-plugin. Use the following snippet to share the dependency

<build>
<plugins>
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<sharedLibraries>
<!-- other shared libraries -->
<sharedLibrary>
<groupId>758f3006–1b00–465d-81c8-dac355598eb3</groupId>
<artifactId>secure-properties-tool</artifactId>
</sharedLibrary>
</sharedLibraries>
</configuration>
</plugin>
</plugins>
</build>

8. Finally, test out the dependency using the following command:

> mvn dependency:tree

--

--

Verma Varun

Mastering automation, improving efficiency and connecting systems.