Using Maven in Liferay Developer Studio

You can take full advantage of Maven in Liferay Developer Studio with its built-in Maven support. In this tutorial, you’ll learn about the following topics:

First you’ll install the necessary Maven plugins for Liferay Developer Studio.

Installing Maven Plugins for Liferay Developer Studio

In order to support Maven projects in Developer Studio properly, you first need a mechanism to recognize Maven projects as Liferay Developer Studio projects. Developer Studio projects are recognized in Eclipse as faceted web projects that include the appropriate Liferay plugin facet. Therefore, all Developer Studio projects are also Eclipse web projects (faceted projects with the web facet installed). In order for Developer Studio to recognize the Maven project and for it to be able to leverage Java EE tooling features (e.g., the Servers view) with the project, the project must be a flexible web project. Liferay Developer Studio relies on the following Eclipse plugins to provide this capability:

  • m2e-core (Maven integration for Eclipse)
  • m2e-wtp (Maven integration for WTP)

All you have to do is install them so you can begin developing Maven projects for Liferay DXP.

When first installing Liferay Developer Studio, the installation startup screen lets you select whether you’d like to install the Maven plugins automatically. Don’t worry if you missed this during setup. You’ll learn how to install the required Maven plugins for Developer Studio manually below.

  1. Navigate to HelpInstall New Software. In the Work with field, insert the following value:

    Liferay IDE repository - http://releases.liferay.com/tools/ide/latest/milestone/
    
  2. Check the Liferay IDE Maven Support option. This bundles all the required Maven plugins you need to begin developing Maven projects for Liferay DXP.

    Figure 1: You can install all the necessary Maven plugins for Developer Studio by installing the Liferay IDE Maven Support option.

    Figure 1: You can install all the necessary Maven plugins for Developer Studio by installing the *Liferay IDE Maven Support* option.

    If the Liferay IDE Maven Support option does not appear, then it’s already installed. To verify that it’s installed, uncheck the Hide items that are already installed checkbox and look for Liferay IDE Maven Support in the list of installed plugins. Also, if you’d like to view everything that is bundled with the Liferay IDE Maven Support option, uncheck the Group items by category checkbox.

  3. Click Next, review the install details, accept the term and license agreements, and select Finish.

Awesome! Your Developer Studio is ready to develop Maven projects for Liferay DXP!

You’ll learn about creating Maven projects in Developer Studio next.

Creating Maven Projects

You can create a Maven project based on Liferay’s provided Maven archetypes.

  1. Navigate to FileNewLiferay Module Project.

  2. Give your project a name, select the maven-module build type, and choose the project template (archetype) you’d like to use.

    Figure 2: The New Liferay Module Project wizard lets you generate a Maven module project.

    Figure 2: The New Liferay Module Project wizard lets you generate a Maven module project.

  3. (Optional) Click Next and name your component class name and package. You can also specify your component class’s properties in the Properties menu.

  4. Click Finish.

That’s it! You’ve created a Liferay module project using Maven!

If you created your Maven project outside of Developer Studio with another tool, you can still manage that project in Developer Studio, but you must first import it. You’ll learn how to do this next.

Importing Maven Projects

To import a pre-existing Maven project into Liferay Developer Studio, follow the steps outlined below:

  1. Navigate to FileImportMavenExisting Maven Projects and click Next.

    Figure 3: Developer Studio offers the Maven folder in the Import wizard.

    Figure 3: Developer Studio offers the Maven folder in the Import wizard.

  2. Click Browse… and select the root folder for your Maven project. Once you’ve selected it, the pom.xml for that project should be visible in the Projects menu.

    Figure 4: Use the Import Maven Projects wizard to import your pre-existing project.

    Figure 4: Use the Import Maven Projects wizard to import your pre-existing project.

  3. Click Finish.

Now your Maven project is available from the Package Explorer. Next you’ll learn about Liferay Developer Studio’s POM graphical editor.

Using the POM Graphic Editor

You’re provided a nifty POM graphic editor when opening your Maven project’s pom.xml in Liferay Developer Studio. This gives you several different ways to leverage the power of Maven in your project:

  • Overview: provides a graphical interface where you can add to and edit the pom.xml file.

  • Dependencies: provides a graphical interface for adding and editing dependencies in your project, as well as modifying the dependencyManagement section of the pom.xml file.

  • Effective POM: provides a read-only version of your project POM merged with its parent POM(s), settings.xml, and the settings in Eclipse for Maven.

  • Dependency Hierarchy: provides a hierarchical view of project dependencies and an interactive listing of resolved dependencies.

  • pom.xml: provides an editor for your POM’s source XML.

The figure below shows the pom.xml file editor and its modes.

Figure 5: Liferay Developer Studio provides five interactive modes to help you edit and organize your POM..

Figure 5: Liferay Developer Studio provides five interactive modes to help you edit and organize your POM..

By taking advantage of these interactive modes, Liferay Developer Studio makes modifying and organizing your POM and its dependencies a snap!

« Using Gradle in Liferay Developer StudioUsing Front-End Code Assist Features in Developer Studio »
Este artigo foi útil?
Utilizadores que acharam útil: 0 de 0