Quick setup of Maven environment

Author: San Nian

This article is mainly for the purpose of quickly building a maven environment, and some concepts will be omitted from their descriptions:


1. What is maven?

Maven is a cross-platform project management tool, mainly used for project construction and dependency management based on the java platform. Simply put, it is to use maven to get the jar package instead of manually adding the jar package


2. What does maven rely on to obtain jar packages?

There is one such file in maven project - pom.xml . It is used to allow users to configure their properties to obtain the corresponding jar package. Here, we briefly understand the writing of pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.test</groupId>   <!-- 标识 -->
  <artifactId>mavenDemo</artifactId>   <!-- 项目名称 -->
  <version>0.0.1-SNAPSHOT</version>   <!-- 版本号 -->
  <packaging>jar</packaging>    <!-- 项目打包后为jar包 -->

  <name>mavenDemo</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>    <!-- 所有依赖的jar包统一放在此节点下 -->
    <dependency>    <!-- 书写依赖,此节点主要有三个属性来定位到一个jar包:groupId、artifactId、version -->
      <groupId>junit</groupId>   <!-- 包名 -->
      <artifactId>junit</artifactId>  <!-- 项目名 -->
      <version>3.8.1</version>  <!-- jar包版本 -->
      <scope>test</scope>
    </dependency>
    <!-- 如果需要书写其它jar包,就继续书写对应的dependency,同上 -->
    <!-- ...... -->
  </dependencies>
</project>

Three, maven download and installation

First of all, you need to install jdk and eclipse on your computer. If you haven't installed it, please configure its environment first. I won't explain it here.

1. Download Maven

Enter the official website: http://maven.apache.org/
write picture description here

write picture description here

2. Unzip Maven as follows and add environment variables to it

write picture description here

write picture description here

write picture description here

3. Edit setting.xml

write picture description here

write picture description here

<localRepository>D:\MyMavenLibs</localRepository>

write picture description here

 <!-- 国内镜像静态服务器: --> 
  <mirror>  
    <id>alimaven</id>  
    <mirrorOf>central</mirrorOf>  
    <name>aliyun maven</name>  
    <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>  
  </mirror>

【Optional】
write picture description here

    <server>  
        <id>tomcat</id>  
        <username>admin</username>  
        <password>admin</password>  
    </server>
   <!-- 对应apache/conf/tomcat-users.xml: --> 
    <role rolename="admin-gui"/>  
    <role rolename="admin-script"/>  
    <role rolename="manager-gui"/>  
    <role rolename="manager-script"/>  
    <role rolename="manager-jmx"/>  
    <role rolename="manager-status"/>  
    <user username="admin" password="admin" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-script,admin-gui"/> 

Fourth, how to use maven to create a Java project in Eclipse IDE?

write picture description here

write picture description here

write picture description here

write picture description here

write picture description here

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326775559&siteId=291194637
Recommended