Maven (v) simple application of Maven in eclipse

Source: Internet
Author: User

1. Import Maven Project

The MAVEN project was written in 4 and is now imported. Select the menu item File, and then select Import, we will see an Import dialog box, select Maven Projects under the Maven directory in the dialog box, and then click Next, and the Import Maven Projects dialog box will appear in the dialog box, click Browse ... Select the root directory of Maven (that is, the directory that contains the Pom.xml file), and the Projects: section of the dialog box displays the MAVEN projects that the directory contains, as shown in Figure 3-1:

After clicking Finish, M2ecilpse will import the project into the current workspace, and after the import is complete, we can see the project structure as shown in the package Explorer view:

We see the main code catalog Src/main/java and the test code catalog Src/test/java The resource directory in Eclipse, the structure of packages and classes is clear, and of course pom.xml is always at the root of the project, and from this view we can even see the dependencies of the project. Junit-4.0.jar, where the actual location points to the MAVEN local repository (I've customized the MAVEN local warehouse address to C:\Users\alex2.m2\repository, and the next chapters describe how to customize the local warehouse location).

2/Create Maven project

It's also easy to create a MAVEN project, choose menu Item---new--and other, select Maven project under Maven in the pop-up dialog, then click Next; in the popup New maven Proje CT dialog box, we use the default options (do not select the Createa simple project option so that we can use Maven archetype), click Next, and M2eclipse will prompt us to select a archetype , we select Maven-archetype-quickstart, then click Next >. Since M2eclipse is actually creating the project using the Maven-archetype-plugin plugin, this step is similar to the previous section where we used archetype to create the project skeleton, input GroupID, Artifactid, version, Package (We do not consider the Properties for the time being), as shown in Figure 3-3:

OK, click on the Finish,maven project and the creation is complete.

3. Run MVN command

Right-click on the MAVEN project or right-click on the Pom.xml file and click Run as (this is a phone shot, not very clear, forgive me) there will be many options, this is the same as our DOS command function is the same

We ran test first, we found an error, and did not provide a compilation environment:

Workaround: In the Eclipse menu, go to Window > Preferences > Java > Installed jres > Execution environments, select JavaSE-1.6, select on the right JDK. Rerun test again, if not, right-click on the project maven > Update Projects (Alt F5), and update it to run again.

We see that we are using jdk1.5, if you want to change the JDK version of what to do, all configurations are the same, configure in Pom.xml, update projects OK

Select the Maven command you want to execute to perform the appropriate build, and we can see the build output in the Eclipse console. One common problem here is that the default option does not have the Maven command we want to do. For example, the default with MVN test, but we want to execute MVN clean test, very simple, choose Maven buid ... With the custom Maven Run command, enter the command we want to execute in the goals entry in the popup dialog box, such as clean test, set Name, and click Run. And, the next time we choose Maven build, or use the shortcut key Alt + Shift + X, M to quickly perform MAVEN builds, the last configuration can be found directly in the history. The following is the interface for customizing the Maven Run command:

Related Article

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.