Embedding Mule in a Java Application or Web app

This page describes how to start and stop Mule from a Java application or to embed it in a Web app (such as a JSP or servlet), and how to interact with Mule from your code in both scenarios.

Starting Mule from a Java Application

Before running Mule in embedded mode in either a Java application or a Web app, be sure to manually update all the required dependencies for your application. The Mule ESB Embedded Single .jar contains all Mule classes, but you need to include the dependencies manually.

To start Mule from a Java application, call one of its configuration builders.

Stopping Mule from a Java Application

Embedding Mule in a Webapp

Listed below are some of the advantages of running Mule standalone vs running it as a web application deployed in an application server (Tomcat, WebSphere, JBoss, etc.)

Wrapper control: Mule Standalone makes use of a Java Service Wrapper which controls the JVM from your operating system and starts Mule. The wrapper can handle system signals and provides better interaction between the JVM and the underlying operating system.

Smaller memory footprint: Mule standalone loads only the required resources for an application; an application server adds its own resources.

Anypoint DataMapper support: DataMapper is supported only on a Mule Enterprise Standalone runtime; other application servers do not support DataMapper.

Deployment and Application Management: Through the Mule Management Console, you have full control of the applications running on Mule Standalone, allowing you to deploy/undeploy applications and restart/stop the server. Other application servers do not support this visibility.

To embed Mule inside a webapp, provide one or more configuration file locations as context params and include a context listener to initialize the Mule Server. If you are using Mule XML configuration, use the following:

Sign up for our Dev newsletter

MuleSoft provides the most widely used integration platform for connecting SaaS and enterprise applications in the cloud and on-premises. Delivered as a packaged integration experience, CloudHub™ and Mule ESB™ (Enterprise Service Bus) are built on proven open source technology for the fastest, most reliable on-premises and cloud integration without vendor lock-in.