Win10 installation maven and related configuration

Posted by blt2589 on Thu, 13 Jan 2022 10:45:09 +0100

catalogue

summary

install

Configure environment variables

Modify local warehouse Path

summary

Installing maven on Win10 is very simple. You only need to download the installation package on the official website and then unzip it. However, the configuration of maven is extremely important, especially the configuration of warehouse path.

install

I installed "apache-maven-3.6.3" this time. I also put the installation package on Baidu network disk. Friends in need can download it.

Link: https://pan.baidu.com/s/1NXkGHGRrWyz_bFlIGYlc6g

Extraction code: 0txi

After extracting it, it means that the installation has been successful.

Let's test it first and open the console.

C:\Users\HP>mvn --version
'mvn' It is not an internal or external command, nor is it a runnable program
 Or batch file.

It is found that maven commands cannot be used directly. It is likely that we have not added maven to the environment variable.

Then I'll switch to the directory we just unzipped and installed, such as "D:\sf\apache-maven-3.6.3\bin" here.

D:\>cd D:\sf\apache-maven-3.6.3\bin

D:\sf\apache-maven-3.6.3\bin>mvn --version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: D:\sf\apache-maven-3.6.3\bin\..
Java version: 1.8.0_66, vendor: Oracle Corporation, runtime: D:\sf\Java\jre1.8.0_66
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 10", version: "10.0", arch: "x86", family: "windows"

After switching, we run maven command again. From the above, we can see that our maven has been successfully installed. For the convenience of subsequent use, we still need to add maven to the environment variable.

Configure environment variables

Right click my computer on the desktop and select Properties:

Maybe everyone's system version has different interface effects. After a little observation, you should find the interface for setting environment variables.

Create a new variable in system variables.

Then configure variable name and variable value. The variable name can be taken according to your habits, but the variable value is the root directory we extracted earlier.

If you are careful, you may find that we can configure "variable value" through "browse directory" or "browse file".

Finally, we add the maven variable we just configured to the "Path" variable. If there is no "Path" variable, we can create a new one. Generally, there will be this variable, but I did encounter a case where there is no "Path" variable on my colleague's computer.

Double click Path:

Now this interface has been very user-friendly. I remember in 1978, it was a large string of text, and they were worried about correcting mistakes. Now, each variable has one line, which is independent of each other and is not easy to correct.

Let's create a new variable and add maven's variable.

The contents are as follows:

%MAVEN_HOME%\bin

Finally, click OK to indicate that the configuration is successful.

Then let's verify whether the environment variable configuration is effective.

Open the console:

Run the following command:

C:\Users\HP>mvn --version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: D:\sf\apache-maven-3.6.3\bin\..
Java version: 1.8.0_66, vendor: Oracle Corporation, runtime: D:\sf\Java\jre1.8.0_66
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 10", version: "10.0", arch: "x86", family: "windows"

Therefore, we have successfully configured maven's environment variables.

Modify local warehouse Path

I remember the path of maven's local warehouse. By default, it is on disk C. considering the particularity of Disk C, I don't recommend that you put the local warehouse on disk C. I put it in disk D as a file "D: \ maven local repository".

We found the file "settings.xml" in the Maven installation directory "D:\sf\apache-maven-3.6.3\conf" and found the "< localrepository >" configuration item:

<localRepository>/path/to/local/repo</localRepository>

It is recommended to copy it and put it outside the comments, otherwise it will not take effect.

As follows:

Then save it.

We verify that the following has been configured successfully. Open the console and run the following command:

C:\Users\HP>mvn help:system
[INFO] Scanning for projects...
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom (3.9 kB at 1.6 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/22/maven-plugins-22.pom

. . .

Until the run is complete, then we open our newly configured warehouse directory.

You can see that many Jar packages have been downloaded, which proves that our newly configured local warehouse directory is valid.

Topics: Java Maven