Create a MAVEN project with eclipse

Source: Internet
Author: User
Tags log4j

The first step is to install the MAVEN for Eclipse plug-in m2eclipse.

Address: http://www.eclipse.org/m2e/download/

Open Eclipse and find m2eclipse in Eclipse Marketplace

In the Find Input box, enter M2eclipse, and then enter,

We want to install the plug-in type 1th, because I have installed, so the display is update and uninstall.

If it is not installed, the install is displayed, and then click this button.

Then click on the "Next" button,

Then select "I accept the terms of the license Agreements" and click the "Finish" button.

Eclipse will then be downloaded and installed, and you will be prompted to restart Eclipse to take effect after installation, so you can restart eclipse.

This way our M2eclipse plug-in is ready to install.

There are some settings that need to be made when the M2eclipse plugin is installed.

Open Windows->preferences and find maven.

The first thing to change is installations,

It comes with one, but it doesn't work, and we want to specify the location of our maven. Click the Add button and find our own MAVEN location.

As above mine is F:\study\tools\apache-maven-3.0.5-bin\apache-maven-3.0.5\.

The user settings is then modified to be the default configuration.

As you can see, its default local warehouse location is in My Documents. M2, we need to modify the location specified for our own localrepostory configured in Settings.xml.

My local warehouse location is: f:/study/maven/repository.

Then click the Apply,ok button.

Ok, this MAVEN configuration is over. Let's use Eclipse to create a MAVEN project.

New->others->maven->maven project, then select Create a simple project (skip archetype selection).

Then the input groupid,artifactid,version,package and so on,

Then click the "Finish" button.

The structure of the project is created like this:

Java source code is placed in the Src/main/java, the test class sources are placed in the Src/test/java, the configuration file used in the project in Src/main/resources, the unit test to use the resource file in the src/test/ Resources.

The default created Pom.xml is not any dependent, if we want to add a dependency then double-click Open pom.xml file, any clicking on the "Dependencies" tab, click the Add button to add the dependency,

Any Click OK adds a dependency of junit.

This is what we know about GroupID and Artifactid, if we don't know?

We can go to the central warehouse to find out.

Where's the central warehouse?

There is a pom-4.0.0.xml in the%m2_home%/lib/maven-model-builder-3.0.5.jar,

Open the Pom-4.0.0.xml file, the URL in the ID-bit repostory is the location of the central repository,

Ok, if we want to use log4j now, first open http://central.maven.org/maven2/

, first tell us not available, view directory contents in http://search.maven.org. OK, let's go in.

Enter log4j in the input box, and then locate,

For example, a number of versions of log4j are listed, and we choose to 1.2.17 this version.

For example, a dependency definition is listed in dependency information and copied and pasted into the pom.xml.

Now you can use log4j in your code,

How do I build a maven project?

Right-click Pom.xml, there are a series of menus such as maven Build,mavn Clean,maven Install,maven test and so on.

Create a MAVEN project with eclipse

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.