Maven-01- install maven-3.6.3 on windows7

1. Goal

Install maven3.6.3 on windows7, set the maven storage folder, set maven's domestic warehouse source address, introduction of maven basic commands, introduction of pom files

2. Description

Maven needs the support of the java environment, so you need to configure the java environment on windows in advance.

Maven official website https://maven.apache.org/

Basic maven commands:

mvn compile 编译项目
mvn test 编译项目并进行单元测试
mvn clean 清除target目录
mvn package 将项目进行编译、测试、打包jar/war/pom
mvn install 将项目进行编译、测试、打包、发布到仓库中

Three, general steps

1. Configure the java environment on windows (omitted).

Install java and configure java system variable path display

C:\Program Files (x86)\Common Files\Oracle\Java\javapath;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Git\cmd;%JAVA_HOME%\bin;C:\Program Files\apache-tomcat-9.0.41C:\Program Files\apache-tomcat-9.0.41;

Make sure you can type the command java -version in the cmd of windows 

2. Download the windows version of maven

Paste here the download link of apache-maven-3.6.3-bin.zip https://mirrors.bfsu.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3 -bin.zip

3. Unzip the downloaded apache-maven-3.6.3-bin.zip to a suitable location (omitted)

4. Add MAVEN_HOME to the windows system variables

Add windows system variables, create a new

● Variable name: MAVEN_HOME

● Variable value: C:\software\apache-maven-3.6.3 (according to your decompression directory, apache-maven-3.6.3 is the root directory, under apache-maven-3.6.3 there are bin directory, boot Directory, conf directory, lib directory)

5. Modify the windows system variable path

Add [;%MAVEN_HOME%\bin] at the end of the system variable Path.

Note that Windows environment variables are separated by semicolons. If your path value has a semicolon at the end; then you only need to write [%MAVEN_HOME%\bin] in brackets this time.

Note save.

6. Modify the warehouse address

Note, the warehouse address defaults to ${user.home}/.m2/repository

You can modify the [C:\software\apache-maven-3.6.3\conf\settings.xml] setting to change the default warehouse storage path

Create a new warehouse folder (omitted), such as: c:\kahn. Pay attention to capitalization. It is recommended that the folder name be consistent with the capitalization in the configuration file.

7. Configure the source address of the maven central warehouse to be domestic Alibaba Cloud

Find the [mirrors] block in the configuration file [C:\software\apache-maven-3.6.3\conf\settings.xml], and add the following paragraph to it

    <mirror>
      <id>alimaven</id>
      <mirrorOf>central</mirrorOf>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
    </mirror>

8. Restart windows to make the configuration take effect (omitted)

9. Test that maven is successfully installed on windows

Execute [mvn -v] in the windows command line, if the maven version number can be returned normally, then the installation is successful.

10. Use the command to generate a maven test project

Execute in the windows command line

mvn archetype:generate -DgroupID=com.hiibm -DartifactId=demo -DarchetypeArtifactId=maven-archetype-quickstart

● Prompt during execution: Define value for property'groupId':, for example, enter xgroupid and press Enter.

● Prompt during execution: Define value for property'package' xgroupid:: xpackage, for example, enter xpackage and press Enter.

● Press Enter all the way for other prompts during execution. Until the project is successful

At this point, you will find that your maven local warehouse folder will have many folders generated. (Omitted, depending on the folder defined by your maven configuration file settings.xml)

At this point, you will find that a folder called demo will be generated in the directory where your command line is located, and this is the project folder.

Fourth, the introduction of the POM file

Below is a simple pom file comment

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>xgroupid</groupId> ---------->组织id
  <artifactId>demo</artifactId>  ---------->模块id或者项目id
  <packaging>jar</packaging> ---------->项目的打包方式,比如war、jar、pom
  <version>1.0-SNAPSHOT</version> ---------->当前项目的版本号
  <name>demo</name>
  <url>http://maven.apache.org</url>
  <dependencies> ---------->依赖列表开始
    <dependency> ---------->第1个子依赖
      <groupId>junit</groupId> ---------->第1个子依赖的具体名称和版本号
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope> ---------->看下面的详细解释
    </dependency>
  </dependencies> ---------->依赖列表结束
</project>


●第15行的<scope>取值的介绍:
test:表示测试依赖范围。即测试时需要,便于和运行时不需要,不会被打包。(也就是本次的这个junit不会被打到jar包里)
compile:默认值,表示编译依赖范围。即编译、测试、运行时都需要,会被打包。默认值compile标明该jar一直全称存在/需要。
provided:表示已提供依赖范围。即编译、测试时需要,运行时不需要,不会被打包。比如servlet-api和jsp-api被tomcat容器提供。
runtime:表示运行时提供依赖范围。即编译时不需要,运行和测试时需要,会被打包。比如jstl、jdbc驱动。
system:范围依赖与provided类似,但是你必须显式的提供一个对于本地系统中JAR文件的路径,需要制定systemPath磁盘路径,system依赖不推荐使用。

 

--------------------------kahn ok---------------------2021 January 27th, 2016------------------------------------------- 

Guess you like

Origin blog.csdn.net/xoofly/article/details/113246499