Using Maven with Developer Studio
This page describes how to use Maven with Developer Studio. It includes the following sections:
Maven Support for Deployable Artifacts
A pom.xml file is automatically generated for each project created in Developer Studio. This file allows you to build the project using Maven. To build individual deployable artifacts using Maven, go to the project location in the command line and run the command mvn clean install
.
One or more of the following deployable artifacts are then created under the target
folder of your project location:
Artifact Type | Project Type |
Apache Axis2 Artifact | Axis2 Archive [aar] |
Web Application | Web Application Archive [war] |
JAX-WS Artifact | Java Archive [jar] |
Endpoint Artifact | xml |
Sequence Artifact | xml |
Proxy Service Artifact | xml |
Local Entry Artifact | xml |
Synapse Configuration | xml |
ESB Mediator | Java Archive [jar] |
Registry Resource | Registry Resource with necessary meta-data |
Registry Handler Artifact | OSGI Bundle [jar] |
Registry Filter Artifact | OSGI Bundle [jar] |
Data Service Artifact | Data Services Descriptor file [dbs] |
Data Services Validator Artifact | OSGI Bundle [jar] |
BPEL Workflow | BPEL Archive [zip] |
Gadget | Dashboard Archive [dar] |
Complex Event Processor Artifact | xml |
Business Rule Server Artifact | Axis2 Archive [aar] |
Carbon UI Bundle | OSGI Bundle [jar] |
Third Party Library Artifact | OSGI Bundle [jar] |
Carbon Application Project | Carbon Application Archive [CAR] |
Working with Maven Multi Module Projects
Developer Studio creates separate projects and a separate Maven pom.xml file for most deployable artifacts. In Maven-centric development, however, you have a parent project and some child modules, including a separate distribution module that is a child module of the parent project. To achieve this model, you can create a Maven Multi Module Project in your workspace, create your artifact projects nested within it, and then create the Carbon Application Project for the distribution module. You can also convert an existing project to a Maven Multi Module Project.
Creating a New Maven Multi Module Project
To create a new Maven Multi Module Project, take the following steps:
- In Developer Studio, click File -> New -> Project.
- In the New Project wizard, expand WSO2 -> Maven Project, click Maven Multi Module Project, and then click Next.
- Â In the Maven Information Settings dialog box, provide Maven information such as GroupID, ArtifactId (also becomes your project name), and Version, and then select the modules to include in project by selecting their projects from the list. Click Finish.
You can now open pom.xml to see the selected projects that are listed as Maven modules.
Convert an Existing Project to a Maven Multi Module Project
To convert an existing project to a Maven multi module project, take the following steps:
- Right-click the project and click Generate POM.
- Select the modules to include in project by selecting their projects from the list, and then click Finish.
Synchronizing Dependencies Between Eclipse and Maven
When you are working with software projects in Eclipse, you often need to refer to third-party libraries in your project. Because your source code is using the APIs and utilities exposed by these libraries, you must add them to the Eclipse project classpath (project buildpath) as dependencies to prevent compilation errors in the Eclipse IDE. If you are using Maven as your build tool, you must add these same libraries as Maven dependencies in your Maven pom.xml file. Likewise, if you want to use a Maven project in Eclipse, you need to synchronize the Maven dependencies with the Eclipse project. Developer Studio provides a simple way to synchronize the dependencies, as described in the following sections:
- Update the POM File with Dependencies from the Eclipse Project
- Update the Eclipse Project with Dependencies from the POM File
Update the POM File with Dependencies from the Eclipse Project
You can update your project's Maven pom.xml file with the current set of third-party libraries in your Eclipse project buildpath. If you add another third-party library to your Eclipse project buildpath, right-click the project and click Maven -> Sync Project Dependencies with pom.xml. The POM file will now contain the dependency you added to your Eclipse project.
Update an Eclipse Project with Dependencies from a POM File
If you want to open a Maven project in Eclipse and continue development, or if your existing Eclipse project maintains its dependencies in a pom.xml file, you can run the command mvn eclipse:eclipse
in the Maven eclipse goal against your project to generate your project descriptors or update existing project descriptors. This feature requires that you create a WSO2 Maven project using Developer Studio 3.0.0 or later. You must also use Eclipse M2Eclipse 1.2 or later and Apache Maven 3.0.3 or later.
For example, let's assume you have a WSO2 Maven project called CustomMediator where you have only source files and a Maven pom.xml file. Take the following steps:
- In a command prompt/shell, go to the file system location of your Maven project, and then enter the
mvn eclipse:eclipse
command as described in the Maven eclipse goal. The Maven project is built as shown in the following image. - In Developer Studio, if the current perspective is not Java EE, click Window -> Open Perspective -> Other -> Java EE.
- Click File -> Import.
- In the Import wizard, expand WSO2, click Existing WSO2 Projects into workspace, and click Next.
- Click Browse and specify the Maven project location in the file system. When you specify the location, Eclipse automatically scans the file system, locates all the projects, and displays them under Projects.
- Select the project and click Finish.
You can now open your project and continue development in Eclipse.