Running Mule From Java


Have you wondered that your Mule application can be run from a Java class ?

Yes, it’s true .. You can run your entire Mule flow from a small java class.

So, how can we run a Mule application from Java ????

To start you Mule flow or app from Java, you need to refer Mule Context.

To know more about MuleContext, please visit :-

Just like Spring Context, Mule will combine all resource files into a single ApplicationContext, whether they are “pure” Spring files or Mule configuration files.

So let us consider, we have our Mule config file named as MuleTest.xml :-


Here you can see set payload component is followed after http inbound endpoint which will send the payload and will be displayed in the browser, which is followed by a logger to log message into console.

Now, let’s create a Java class that will run our Mule application as follows :-


As you can see that in the Java class, we are using MuleContext for starting our application.
Here using the following line in the code :-

SpringXmlConfigurationBuilder configBuilder = new SpringXmlConfigurationBuilder(
We are loading our MuleTest.xml file.

Now, if there would have multiple XML file in our application, we would have used a comma-separated list or an array of configuration files the following :-

SpringXmlConfigurationBuilder configBuilder = new SpringXmlConfigurationBuilder(new String[] { “mule-config.xml”, “another-config.xml” });                

That’s it .. Now let us run our Java class to start our Mule application as follows :-


Now, we find that the Mule application is getting deployed in Mule server and running :-


So we will be testing our flow by hitting the url :- http://localhost:8060/startfromjava in browser and will get the following result :


Also in the console we will get the following log by the logger :-



That’s it … Now you can try this example by your own and can run your single or multiple Mule XML from you Java code..
Happy coding and share your knowledge everywhere :)




Anirban Sen Chowdhary

Anirban Sen Chowdhary is an information technology professional currently working on Java/J2ee, Esb and Integration platform. For more information, please visit and you can also follow

You may also like...

1 Response

  1. Yuki says:

    Thanks for the tutorial. I follow it and I am able to run it successfully, but the console returns the following warning. Will you by any chance know how to fix it?

    [main] org.mule.module.ognl.expression.OgnlExpressionEvaluator: OGNL module is deprecated and will be removed in Mule 4.0. Use MEL expressions instead.

Leave a Reply to Yuki Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>