MAVEN Learning Phase 3rd---m2eclipse use

Source: Internet
Author: User
Tags maven central sonatype

I. Introduction of M2ECLIPSE

Like Nexus, M2eclipse is also an open source tool produced by Sonatype, which is based on the Eclipse public license-v.10 open source license, which users can download and use for free, and view their source code m2 The official site address for Eclipse is http://m2eclipse.sonatype.org/.

M2eciipse provides the full range of Maven integrations for the eclipse environment with the following key features:

Creating and guiding Maven projects

Manage dependencies and integrate with Eclipse's Ciasspath

Automatic Download dependency

automatic parsing of dependent sources and Javadoc packages

Create a project using MAVEN archetype

Browse and search remote maven repositories

materialize a project from Maven Pom

Check out MAVEN projects from the SCM Warehouse

automatic adaptation of nested multi-module MAVEN projects to Eclispe

Integrated Web Tools Projects (WTP)

Integrated Subclipse

Integrated Mylyn

visualization of Pom edits

Graphical Dependency analysis

TwoM2eclispeSimple to use 2.1 new MAVEN project

It's easy to create a new maven in M2eclipse , and in the menu bar, select File→new→other. You can now see the wizard shown:

After you select maven Project, the wizard prompts the user to choose whether to skip archetype and create the simplest Maven project, and the simplest project will contain only The most basic MAVEN project directory structure , readers can choose according to their own needs.

If you choose to create the project using archetype, after clicking the Next button, the wizard prompts the user to select Archetype, as shown in

As shown, there are 4 archetype catalog available for users to choose from, including maven-archetype-plugin built -in intemal, local warehouse Default Local,m2eclipse download to the Nexus Indexerincluded in the warehouse index, and all of the 3 merged Catalogs. If the archetype catalog is not very clear. In general, you only need to select internal. Then select a archetype, such as Maven-archetype-quick-start, and finally click the Next button.

The next thing to do is enter the project coordinates group ID, Artifact ID, version, and package name. This step is similar to creating a project using archetype on the command line, and if archetype has other configurable properties, the user can also be configured here, as shown in.

Once you click the Finish button,m2eclipse quickly creates a Maven project in the workspace, which is also an Eclipse project.

2.2 Importing MAVEN Projects

Compared to creating a new Maven project, the actual work is more common in the lead-in-person MAVEN project. M2eclipse supports a variety of imported FANGWU, the most common of which is the Maven project for the local file system and the Maven project in the SCM warehouse .

Click File in the menu bar and select Import to start the pilot project as shown in:

You can see that there are 4 ways to lead in the Maven class, which is oftenFirst KindAndThe second Kind, i.e.import in the SCM warehouseMAVEN Projects andimporting the local file systemMaven project. In the figureInstall or deploy an artifact to a Maven repositoryAllows the user toarbitrary files are installed to Maven's local repository . If the file does not have a corresponding POM, you need to define MAVEN coordinates for it. In the figurematerialize Maven ProjectsTo enable usersthird-party MAVEN projects, users only need to provide somekeywords such as nexus-api ,then select the project you want to lead.,M2eclipseThe corresponding POM information can be found based on the index. If the POM contains the SCM information,M2eclipseYou can download the source code of the project directly and guide the person toM2eclipseIn This feature is useful when you use a third-party class library and want to study its source code, and you no longer need to open a browser to find information about the project, simplyM2eclipseThe third-party project will be completed in a few steps. Of course, the premise of this feature is that the third-party class library provides the correct SCM information. Most open source projects provide complete information when submitting artifacts to the MAVEN central repository, with the exception that, in order to avoid incomplete information entry into the MAVEN central repository, the latest rules have forced the submitter to provide complete information such as SCM, licenses, and source packages. This will undoubtedly helpM2eclipsePerform better.

2.2.1 Importing local MAVEN projects

Now in detail how to guide your local MAVEN project: Select the existing MAVEN projects option in the Pop-up dialog box and select the directory where the local project is located, as shown in. M2eclipse is able to automatically identify the MAVEN projects contained in the directory, and if it is found to be a multi-module project, all modules will be listed. The user can select the module to be directed according to his/her needs, then click the Finish button two m2eclipse will perform the guided project information, update the download project dependencies, and rebuild the workspace, depending on the actual project situation, this process may take dozens of seconds to more than 10 minutes:

2.2.2 Importing MAVEN projects from the SCM Warehouse

Usually our project source code is stored in the SCM warehouse, such as Subversion Repository, readers can of course use the Subversion command to check out the source of the project to the local, and then import into the m2eclipse , but m2eclipse enables users to direct the MAVEN project directly from the SCM warehouse.

To get a MAVEN project from the SCM, you first need to make sure that the Eclipse plug-in that integrates the SCM, such as Subclipse, also requires M2eclipse 's ancillary components maven SCM Integration and the corresponding SCM handler, such as the integrated Subclipse Maven SCM handler for Subclipse. If these components are installed correctly, you can select the check out Maven Projects FROMSCM in:

After clicking the Next button, select the SCM type and enter the SCM address as shown in:

After clicking the Next button, the user can select the local location of the project import and click the Finish button,m2elipse will use the SCM tool to check out the project in the background to perform Maven build.

Third, visit the MAVEN library

With m2eclipse, users can browse the local and remote maven repositories directly in Eclipse, and be able to search for artifacts based on the indexes of these silos and Java class search . This eliminates the hassle of leaving Eclipse to access local file systems or browsers, improving the efficiency of daily development.

3.1 Maven Warehouse View

M2eclipse provides a MAVEN warehouse view that allows users to easily browse the contents of local and remote warehouses, although the view is not turned on by default. To open the Maven warehouse view and select the windows→show view→other option in the Eclipse menu bar, Eclipse pops up a dialog box that lets the user select the view to open, and then choose Maven Repositories under the Maven class. As shown in the following:

You can see the Maven warehouse view below the Eclipse window, which contains the 4 types of Maven repositories, namely:

Local Warehouse

Global Warehouse

Project Warehouse

Custom Libraries

As shown in the following:

Where the local repository contains the maven local repository and the project for the current Eclipse workspace , and the Global warehouse defaults to the Maven Central warehouse , However, if a mirror is set in the Settings.xml, the global repository is automatically changed to a mirrored warehouse. Finally, if the current MAVEN project is POM. Other warehouses are configured in XML, and they are automatically added to the Project Warehouse category. The information for these warehouses originates from the user's settings. xml file and the pom.xml file for the MAVEN project in the workspace .

The user can quickly browse the contents of the warehouse in a tree structure, double-click the leaf node and open the Pom file corresponding to the component, as shown in.

As you may have guessed,M2eclipse does not actually store the contents of all the warehouses, so it consumes a lot of disk and network bandwidth. So, like the Nexus,M2eclipse uses nexus-indexer to index the contents of the warehouse . in the case of the Global warehouse Central, the user needs to build the index of the warehouse and right-click on the warehouse as shown in the first use of M2eclipse 's warehouse browsing and search functionality.

The

rebuild Index lets re-download the full remote index , because the current warehouse is central , the index file is large, so rebuilding the index takes a long time. update Index makes Download the index file in an incremental manner. If it is local warehouse , update Index , and re-traversing the local repository's file indexing .

There are several options in the menu,Disable index Details lets m2eclipse Close the index of the warehouse so that users will not be able to browse the contents of the warehouse or search for it. Minimum Index Enabled means that only the coordinates of the warehouse content are indexed , and Enable full index not only indexes the coordinates of the warehouse contents , it also indexes the Java class information contained in these files, enabling users to search for Java classes in the repository .

3.2 Searching for build and Java classes

With the warehouse index, users can search for maven artifacts by keyword. You can get the widget search box by clicking Navigatein the Eclipse menu bar and selecting the Open Maven POM option. Enter a keyword to get a list of results, and click the list item to expand further to see the version information, as shown in. Double-clicking a specific version of the widget allows m2eclipse to open the corresponding pom file directly.

If the Enable full indexdt option is turned on for the warehouse, that is, the Java type information is included in the index, the widget can be found using the Java class name keyword. Click Navigatein the Eclipse menu bar and select Open type from maven to get the class search box. After entering the keyword, you will get the search results shown. Similarly, a user can click a list item to expand its version, or double-click a specific version to open its pom. Without leaving eclipse, users can search for the class library and Java classes they want to use at any time, andm2eclipse simply requires the user to provide some necessary keywords, which is undoubtedly very convenient.

Iv. Management of Project dependencies

The traditional way to add Maven dependencies is to search for the coordinates that depend on it, and then configure the project's pom. Xml file to include the dependency element . Of course, this can be done in m2eclipse , but m2eclipse provides a more convenient way to add dependencies , and the user relies on the keyword search directly and from Select it in the results . In addition,M2eclipse provides a rich visualization interface to help users analyze the dependencies in a project and how they relate to each other.

4.1 Adding dependencies

There are several ways to add dependencies in m2eclipse , and Direct editing of Pom.xml is one, but here are two more convenient ways to do it.

First Kind

First the user can be on the project or POM. Right-click on the XML, then select Maven, and then select Add Depenclency dependency, as shown in:

In the dialog box that pops up, the user only needs to enter the necessary keywords , select the dependencies and versions to add, and set the correct dependency range , and then click the OK button. Dependencies are automatically added to the Pom.xnil, as shown, adding a dependency to the project javax.servlet:servlet-api:2.5 , and a range such as provided is selected below the diagram.

The second Kind

The second way to quickly add dependencies is to use the m2eclipse Pom Editor . By default, users double-click the project's pom.xml to open the Pom editor, and there are a number of tabs underneath the Pom compiler, including overview , dependencies , plugins , reports , dependency levels , dependency Graph ,effective POM and so on. where dependency (Dependencies) can be used to add , delete , and edit dependencies, as shown in the following download.

Note: If you double-click the interface above, you cannot see it. Perhaps because the installation of the M2E plug-in itself is not complete, there is no POM editor. So you need to download the zip package for Pom Editor:

http://download.csdn.net/detail/honestjiang/8508393

After decompression, directly into the original M2E plug-in package plugin under can, that is, m2eclipse\eclipse\plugins\org.eclipse.zest.xxx two zip, restart, right-click pom.xml that there is Pom The editor opens the way.

Click the Add button above to get the added Dependency dialog box as shown:

In addition, you can see that the user can view and edit the details of the dependency. after adding a project dependency , if m2eclipse does not automatically update dependencies to the project's build path , the user can force a request M2eclipse Updated by the project or POM. Right-click on the XML, select Maven, and then select Update Dependencies or Ctrl+s save.

4.2 Analysis Dependencies

Describes how to use maven-dependency-plugin to analyze and optimize project dependencies, and MAVEN users can view project dependencies and their relationships in a tree-like manner on the command line; with M2eclipse, This visual analysis will be clearer and more intuitive.

Open the dependency hierarchy item (Dependency Hierarchy) in the Pom editor to see the dependency hierarchy shown in the diagram.

The list on the left shows the tree-dependent hierarchy of the project, and the list on the right is the dependency that all Maven eventually resolves. By default, two lists show dependent artifact, version, and scope. To see the dependent GROUPLD, you can click the second button at the top right of the list to show GROUPLD.

With such a dependency level diagram, the user can clearly see how all the dependencies come into the project, which is probably a direct dependency , so on the left it is a top-level node ; maybe it's a transitive dependency , so this The tree level will tell the user what the pass path is, and if the dependency is another module of the same MAVEN project , then its icon will be different from other dependencies, but the look of a folder If the user clicks any item in the resolved dependency list on the right, the left side is automatically updated to the dependent delivery path.

If you think reading this blog gives you something to gain, you might want to click "recommend" in the lower right corner.
If you want to find my new blog more easily, click on "Follow Me" in the lower left corner.
If you are interested in what my blog is talking about, please keep following my follow-up blog, I am "sunddenly".

This article is copyrighted by the author and the blog Park, Welcome to reprint, but without the author's consent must retain this paragraph, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility

MAVEN Learning Phase 3rd---m2eclipse use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.