Mule and Maven
Maven is a project management utility that you can use to develop projects in Mule. Though highly recommended, Maven is not strictly necessary to develop applications in Mule. In an effort to support users working on Maven integration projects, Mule provides the built-in functionality to be enable Maven support for Studio projects.
-
Build and run a new Maven project in Studio. If you’re starting from scratch and you want to use Maven to build your project, begin by creating a new Maven-based project in Studio. You can run the project with Maven from the command line, or directly in Studio. See content below for details.
-
Convert a Maven project into Studio for import. If you already have a Maven project you want to work on with Studio, use the built in functionality in Studio to import the pom.xml file using the
studio:studio
goal. Access Converting Maven into Studio for details. -
Convert a Studio project into Maven for export. If you have built a project in Studio and want to convert it to a Maven project for export, you can use the built-in support in Studio to "Mavenize" the project. Access Converting Studio into Maven for details.
Building and Running a Maven Project in Studio
You can adjust your Studio preferences so that Studio automatically generates a pom.xml
file upon project creation. The following procedure outlines the steps to create a new Maven-based project in Studio.
-
Navigate to Mule Studio > Preferences (or Windows > Preferences in Windows).
-
In the Preferences panel, click to expand Mule Studio, then select Maven Settings.
-
Click to select both Enable Maven support in Mule Studio and Enable automatic maintenance of pom.xml.
-
Adjust the filepath of the Maven installation home directory on your local drive, if you wish, then click OK to save changes.
-
Under the File menu, select New > Mule Project.
-
Enter a Project Name.
-
Click Create POM file for project and maintain with Maven. Mule automatically populates three fields so as to create a
pom.xml
file for your project.-
Group ID: Your company or development team identifier for Maven
-
Artifact ID: Your application or project identifier for Maven
-
version: Version of your artifact for Maven
-
-
Adjust the default contents for the above fields as necessary, then click Finish to create your Maven project in Studio.
-
Studio adds a new
pom.xml
file to your project. Double-click thepom.xml
file to view the contents in Studio.If you manually edit your pom.xml file, Studio updates the classpath of project with any new dependencies. In other words, Mule runs the studio:studio
goal in the background to save any changes to the project. -
Build and save your Maven project in Studio.
-
To run your application as a Maven project, right-click your project name in Package Explorer, then select Run As > Mule Application with Maven.
-
Alternatively, you can package your Mule project from the command line by executing the following syntax:
mvn package
Mule packages the project in a .zip
file. Deploy the.zip
file in the target folder to your Mule ESB instance to run the application.
Disabling Maven Support in Studio
You can adjust your Studio preferences so that Studio does not auto-generate a pom.xml
file for new projects. The following procedure outlines the steps to disable Maven support in your instance of Studio.
-
Navigate to Mule Studio > Preferences (or Windows > Preferences in Windows).
-
In the Preferences panel, click to expand Mule Studio, then select Maven Settings.
-
Click to deselect both Enable Maven support in Mule Studio and Enable automatic maintenance of pom.xml.
-
Click OK to save changes to Preferences.
When you create a new project in Studio, you are no longer able to click Create POM file for project and maintain with Maven in the third panel of the New Project wizard.
Disabling Maven Support in a Single Studio Project
If you have created Maven project in Studio and wish to disable Maven support for that particular project, right-click the project name in the Package Explorer, then select Maven Support in Studio > Disable Support. Though it does not remove the pom.xml
file, Studio ceases to maintain it for the project.
You can re-endable Maven support via the Studio menu item if you did not delete the pom.xml
file. Right-click the project name in the Package Explorer, then select Maven Support in Studio > Enable Support.
If you disable Maven support in your Studio project and delete the pom.xml file, you cannot re-enable it via the Maven Support in Studio menu item. To convert your Studio project into Maven, consult the Converting Studio into Maven documentation.
|
See Also
-
Convert your existing Maven project into Studio. Import the project, then run it as a Maven project directly in Studio.
-
Convert your Studio project to Maven for export.
-
Explore how to use Studio and Subversion.