Integration & IT Modernization

Exporting Common Mule Project as Jar

You might be puzzled why I’m posting such a simple thing. Let me tell you why I’m doing this post at this very moment.

I do posting under two scenarios. Happy scenario: I come up with a topic, think it through and post it. Unhappy scenario: I did something a few months or a few weeks ago, then I burn a few hours trying to re-discover the steps, because my application doesn’t work 🙁

I want to have a succinct summary of the steps to export a common Mule project as a jar file, then re-import into another project. So the common flows can be referenced in the new project.

Step 1. assuming your common project is created, tested and works well.

You can create the jar one of the two ways:

1.1 just right click on the project name, select export, then Java, and pick “JAR file”, set the file name, you got your jar.

1.2 if you use maven, then you need to update your project pom.xml, make sure you change packaging from “mule” to “jar”. Something looks like the following:

<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>prft-logger-impl</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

you run your maven build and pick up your jar file. You can do the full blown “mvn clean install” from command line, or if you are lazy, just try to run the project in the studio, it would generate the jar file in under the “target” directory.

If you care to open the two jar files, you’ll notice maven did a “cleaner” job of packaging the jar then studio. Either way I did it, it appears to be working for me.

Step 2: Reference the jar from your new Mule project
2.1 You can click on your new project properties, select build path, then add external libraries, finally select your exported jar previously.

2.2. If you have maven project, depends how good your pom.xml is, you may need to add a dependency to bring the new jar file. Or you can still do ad doc importing like in step 2.1

Step 3: bring in the flow configuration file from the common jar with spring import

In your Mule configuration XML file, insert something like the following into your project:

<spring:beans>
<spring:import resource=”classpath:prft-logger-impl.xml”/>
</spring:beans>

Now you should be able to call the flows inside the imported XML file.

That’s about it. Have fun!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to the Weekly Blog Digest:

Sign Up
Follow Us
TwitterLinkedinFacebookYoutubeInstagram