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]|
|Proxy Service Artifact||xml|
|Local Entry Artifact||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]|
|Composite Application Project||Composite Application Archive [CAR]|
CAR Deploy plug-in
You can generate a CAR file for your Composite Application Project (C-App) and deploy it to one or more servers at once using the CAR Deploy plug-in for Maven. For more information, see Deploying a C-App to multiple servers using the Maven plug-in
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 Composite 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.* 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:eclipsecommand 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.
Maven Release plug-in
You can use the Maven Release plug-in to package and release your Developer Studio projects. As a practice, at the development stage of the project, it is the SNAPSHOT version of the artifacts that is used. This is similar to the next major/minor version to be released. For example, if the next planned release version is 1.1.0, it is 1.1.0-SNAPSHOT that is used for versioning in the development stage.
Follow the steps below to deploy WSO2 artifacts to a nexus repository:
- Make sure you are using WSO2 Developer Studio 3.7.1 or upwards.
pom.xmlfile, configure the SCM configuration. For example,
<scm> <connection>scm:svn:https://svn.wso2.com/wso2/interns/2013/vijithae/release/trunk</connection> <developerConnection>scm:svn:https://svn.wso2.com/wso2/interns/2013/vijithae/release/trunk</developerConnection> <url>https://svn.wso2.com/wso2/interns/2013/vijithae/release/trunk</url> </scm>
Point to the nexus repository of the project. For example,
<distributionManagement> <repository> <id>deployment</id> <name>Internal Releases</name> <url>http://localhost:8081/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> <id>deployment</id> <name>Internal Snapshot Releases</name> <url>http://localhost:8081/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement>
wso2-release-pre-prepare-pluginand tag base. For example,
<plugin> <artifactId>maven-release-plugin</artifactId> <version>2.5</version> <configuration> <preparationGoals>clean</preparationGoals> <completionGoals>org.wso2.maven:wso2-release-pre-prepare-plugin:1.1.0:pre-prepare</completionGoals> <tagBase>https://svn.wso2.com/wso2/interns/2013/vijithae/release/tags</tagBase> </configuration> </plugin>
- Execute the
mvn release:preparecommand inside the Maven multi module project. Give appropriate values for release, development, and tag versions when prompted.
- Execute the
mvn release:performcommand inside the Maven multi module project.
For complete information on the Maven release plug-in, see the Maven Release Plug-in page on the Apache website.