How to use Eclipse to build a MAVEN environment and common errors

Source: Internet
Author: User
Tags aliyun

This blog is suitable for 0 basic learning Maven, setting up MAVEN and running a project, common mistakes, I will write at the end to understand, see whether it is the same as the mistakes of everyone, or the bracketed comment section of the article will also write some points of attention.

The first step is to download maven and configure the MAVEN environment variables ( if the Java_home directory is configured separately when you configure the JDK)

1. Download maven http://maven.apache.org/download.cgi from the official website

    

2. Download down, put on a disk path, the disk path is best not to contain Chinese (because some foreign projects do not recognize Chinese)

Step Two: Configure the MAVEN environment  

1. Configure Environment Variables

The environment variables are configured in these two

   2. Create a new folder, empty on the line, I was built here in D:\repository

    

3. Configure MAVEN's local repository (in fact, it is so large, is to configure the path to put the jar package)

Open the extracted apache-maven-3.39 folder, open the Conf directory, there is a settings.xml, open this file, find the comments section <localRepository> tags, set the path of the warehouse ( Be sure to remember to copy the path from the note. )

·

    This is the local warehouse path, I previously only configured the local warehouse, did not configure the Central warehouse, follow the steps below to create a MAVEN project has been an error,

In fact, the central warehouse is, if your local warehouse can not find the jar package, it will be the default network download. This to remember configuration

<mirror>      <id>nexus-aliyun</id>      <mirrorOf>*</mirrorOf>      <name> Nexus aliyun</name>      <url>http://maven.aliyun.com/nexus/content/groups/public</url>    </mirror>

4. After configuring these, MAVEN basic configuration is almost, see whether the configuration is successful, that is, open cmd, direct input mvn-v, the following configuration is successful

Step three: Configure the MAVEN environment in eclipse

  We recommend that you first directly follow my steps in the configuration, if the error, first to replace eclipse a new workspace, change workspace everyone should be

    1. Check if Eclipse has its own Maven plugin, just to see if there is a maven, if you have to skip this step, if not, follow the steps below to install a MAVEN plugin

If not, open Help---> Iinstall New software

If the download is complete, restart Eclipse, then open windows--preferences and find Maven .

2. Configure the MAVEN environment for Eclipse

Click Finish, tick your maven, then apply

        Then click User Settings, select the Settings file under Maven conf

Configuration of the Gaocheng.

Fourth step: Create a MAVEN Web project with Eclipse

I'll create a Web project here and choose the War package.

The code in Web. XML is as follows

<?xml version= "1.0" encoding= "UTF-8"? ><web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://java.sun.com/xml/ns/javaee" xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee/http Java.sun.com/xml/ns/javaee/web-app_2_5.xsd "id=" webapp_id "version=" 2.5 ">  <display-name> day01-maventest</display-name>  <welcome-file-list>    <welcome-file>index.html</ welcome-file>    <welcome-file>index.htm</welcome-file>    <welcome-file>index.jsp</ welcome-file>    <welcome-file>default.html</welcome-file>    <welcome-file>default.htm </welcome-file>    <welcome-file>default.jsp</welcome-file>  </welcome-file-list> </web-app>

In addition, we have found that the default JDK is version 1.5, here to teach you how to modify the JDK version, open the project Pom.xml

Add this Code

<properties>    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>    < Maven.compiler.source>1.8</maven.compiler.source>    <maven.compiler.target>1.8</ Maven.compiler.target>  </properties>

Then update

That's when the JDK turns 1.8.

Configure to here if like me, there is no error, then congratulations, the basic configuration has been completed, the following to write a servlet to run a bit.

The servlet was written under Main/java.

OK, and the error, this is because the servlet running the jar package, this time to Maven is the most important, is how to import the external jar package, also open the Pom.xml file

When finished, CTRL + S saves the Pom.xml file, and all errors are not reported at this time.

Fifth step: Run the MAVEN Web program

  

Click to enter in:

  

  

Congratulations! The Gaocheng!

How to use Eclipse to build a MAVEN environment and common errors

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.