Maven Learning (i)--installing MAVEN and configuring Maven in eclipse

Source: Internet
Author: User
Tags unique id

Installing and configuring MAVEN environment variables
  • Requires a Java environment already in the computer
  • In the console, enter: echo %JAVA_HOME% See if you can display the path information of Java home;
  • In the control bar input: java -version See if Java version information is displayed;
  • Download official website: http://maven.apache.org/download.cgi
  • Download the compiled version apache-maven-3.3.9-bin.zip and unzip it toC:\Park_Software\apache-maven-3.3.9
  • To configure environment variables:
  • New environment variable: M2_HOME = C:\Park_Software\apache-maven-3.3.9 Note that you cannot add a semicolon after the home variable;
  • Add the PATH variable:;%M2_HOME%\bin;
  • Check whether the configuration is successful in the console:
  • CMD input:echo %M2_HOME%
  • CMD input:mvn -v
  • If the display is normal, the configuration succeeds.
  • To modify the Maven warehouse path location:
  • For example, if I want the warehouse location to be located on D, then create a new folder on the D drive:D:\m2\repository
  • Configuration C:\Park_Software\apache-maven-3.3.9\conf files under the Config folder setting.xml :
  • Locate the localrepository tag and modify it to: <localRepository>D:/m2/repository</localRepository> ;
  • setting.xmlCopy the file to the D:\m2 folder.

    MAVEN Installation directory Analysis

    M2_home points to the MAVEN installation directory and enters the directory and finds the following files:

  • Bin directory
  • The directory contains mvn scripts that are running, which are used to configure Java commands;
  • Boot directory
  • Contains only one file: plexus-classworlds-2.5.2.jar is a classloader framework, equivalent to the default loader for Java classes.
  • Conf Directory
  • Contains settings.xml , an important configuration file that can globally customize the behavior of Maven.
  • Lib Directory
  • This directory contains all the Java class libraries required by the MAVEN runtime.
  • LICENSE.txt
  • NOTICE.txt
  • Third-party software included with Maven is documented.
  • README.txt

Set HTTP Proxy

(prior to installing the Maven plugin in eclipse failed many times, I do not know if the reason for not setting up the HTTP proxy before, so it is better to configure it)
First in the cmd input: ping repo1.maven.org , if you can not ping the same, you must first set up the agent, set up the way:
Enter the directory ~/.m2/ directory, locate the settings.xml file (if not, %M2_HOME%/conf/settings.xml copy it directly to the directory), and <proxies> add the following information to the tag:

<Proxies><Proxy><Id>my-proxy</Id><Active>true</Active><Protocol>http</protocol> < host>114.212.80.250</host> Span class= "Hljs-tag" ><port>80</ port> <username>park</username> < Password>****</password> << Span class= "Hljs-name" >nonproxyhosts>www.park.com|*.host.com</ nonproxyhosts></PROXY>   

Where the label is changed to its own IP address, host name and password.

Configuring Maven in Eclipse
    • Open Eclipse, tap the Help tab, tap Install new software , and select Add options:
    • NameEnter in field: m2e ;
    • LocationEnter in field: http://download.eclipse.org/technology/m2e/releases ;
    • Select the Maven plugin from search, then click Next.
    • Installing the plug-in may take a while to restart Eclipse.
Create a MAVEN project in eclipse

In Eclipse, click File -> New -> Others -> Maven Project Create your own MAVEN project.
Enter your own name at Groupid,artifactid, as shown in:

    • Group Id: Defines which group the project belongs to, which is often associated with the organization or company where the project is located. For example, Apache has created a project named Mymaven, then GroupID is: com.apache.myMaven;
    • Artifact ID: Defines the unique ID of the current MAVEN project in the group. For example, the project Com.apache.myMaven has the following artifactid:mymaven-util, Mymaven-domain, Mymaven-web and so on;

Eclipse automatically generates MAVEN projects, directory structure:

Directory Analysis:

    • src/main/java: This directory mainly places Java source code;
    • src/test/java: This directory is mainly used to store test code;
    • Maven Dependencies: This is where Maven managed jar files are mainly placed;
    • target: Used to store maven compiled bytecode files;
    • pom.xml: All called Project Object Model , the Project object model, which defines the basic information of the project, describes how the project is built, declares the project dependencies, and so on.
    • src: Used to store resources such as other files that are used in main and test.

In the App.java in the src/main/java directory, there is already a HelloWorld.java simple applet that can be tested and run.

Packaged

You can pom.xml specify the type to package in, and the default is if unspecified .jar .
The packaging process is: Under the project root directory, execute the command mvn clean package , and then you can ./target/ find the package that you just packaged in the directory jar .

This completes the MAVEN installation, how to create a new MAVEN project in Eclipse, and how to package the project, followed by a practical project to further understand Maven.

Maven Learning (i)--installing MAVEN and configuring Maven in 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.