If you are doing java development, there will be various jar packages in your project, but manual copying is error prone, and the version dependency requires you to find jar packages everywhere to download, so it is necessary for you to learn maven to help you manage jar packages and get twice the result with half the effort~
Now let's ask and answer quickly to find out what's going on maven~
Get to know Maven quickly
1. What is Maven?
maven is a top-level open source project of apache foundation. It is an auxiliary development tool
2. Why use maven?
a. maven can be used to manage both jar packages and projects. maven can be used to manage dependencies between small projects and improve development efficiency
b. It is more convenient and less error prone than manually copying jar packages
3. What are the characteristics of Maven?
Simple project settings that follow best practices
All projects follow consistent rules
4. What did Maven do?
Core role:
1. maven can be used to manage jar packages, and maven can be used to manage dependencies between small projects
2. Use maven to enforce the directory structure of the project according to regulations and rules
3. The application of maven will make the jar package dependency and inter project dependency of the project, and the directory structure "standardized"
maven's project structure:
Use of maven
If you know what maven is, you might as well try it and deepen your understanding. How do you know how good it is without trying~
1. Install maven
1. Download Maven from the official Apache website www.apache.com Org, Download apache-maven-3.6.3-bin Zip, unzip after completion
2. Configure the download path of the jar package and modify the image file setting XML (a large number of comments have been deleted from the following files to make it clearer)
<?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <!--local maven Library Configuration--> <localRepository>D:\mavenalibaba</localRepository> <pluginGroups> </pluginGroups> <proxies> </proxies> <servers> </servers> <mirrors> <!-- Ali's maven Library download address configuration--> <mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> </mirrors> <profiles> <profile> <id>nexus</id> <repositories> <repository> <id>central</id> <url>http://central</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <url>http://central</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <!-- selfwrite --> <activeProfiles> <activeProfile>nexus</activeProfile> </activeProfiles> </settings>
3. Configure maven environment of idea
File - > Settings - > search Maven
Create maven project
1.idea creates maven project
File->New->Project-Maven
Select whether you want to create a java project or a web project, and select the corresponding entry above
Fill in the project name and storage address
Click next
Click Finish to complete the creation
If your maven project does not have a corresponding src structure, you can refer to this article~
https://www.cnblogs.com/jsoso/p/11208065.html
2. Note:
When creating a maven project, pay attention to choosing your own java version and Maven environment, otherwise using the default may cause more errors
3.pom file:
By editing this file, we tell maven the jar package you need, and it will download the corresponding jar package together with the jar package it depends on.
pom file set compilation level
You can set the compilation level in pom so that you don't have to change it manually. Even maven update won't be the same as before, which is easy~
Put the following code in the specified location (the complete pom.xml file is below, and then turn it over ~)
1. <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
2 <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
Test jar package download
Write the following code in the pom file
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
Click save, then go back to your local maven library and find that the specified package has been downloaded. maven will help you with the other packages that the specified package depends on
The pom file is shown below
<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.xxx</groupId> <artifactId>testspring_xml</artifactId> <version>0.0.1-SNAPSHOT</version> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.3.7.RELEASE</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.0.2</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>${project.build.sourceEncoding}</encoding> </configuration> </plugin> </plugins> </build> </project>
Loading process of maven:
If you know the functions of maven, you might as well try to change the previous java projects and use Maven to manage them~