Maven
Why should I learn this technology?
-
In Java web, we need to use a large number of jar packages, which we import manually;
-
How can we make something automatically import and configure this jar package for us
Thus, maven was born
-
The advantage of maven is that it will help you import other jar packages that this jar package depends on.
1.1Maven project architecture management tool
We are currently used to facilitate the import of jar packages!
Maven's core idea: Convention is greater than configuration
-
There are constraints. Don't break them.
Maven will specify how you write our Java code, which must be in accordance with this specification
1.2 download Maven
After downloading, unzip it;
1.3 configuring environment variables
In our system environment variables
Configure the following configurations:
-
M2_ bin directory under home maven
-
MAVEN_HOME maven directory
-
Configure Maven in the path of the system_ HOME
Test whether Maven is installed successfully and ensure that the configuration must be completed!
1.4 Alibaba cloud image
-
Mirroring: mirrors
-
Function: speed up download
-
-
Alibaba cloud image is recommended in China
-
Configuring alicloud images
-
Find the settings in conf under D:\Environment\apache-maven-3.8.1 XML, opening
-
Put the following code into the settings of the following picture XML, find < mirrors > < / mirrors >, and put them in the middle, as shown in the following picture.
-
<mirror> <id>nexus-aliyun</id> <mirrorOf>*,!jeecg,!jeecg-snapshots</mirrorOf> <name>Nexus aliyun</name> <url>http://maven.aliyun.com/nexus/content/groups/public</url> </mirror>
1.5 local warehouse
Local warehouse, remote warehouse;
Set up a local repository: localRepository
-
Create a new Maven repo folder under D:\Environment\apache-maven-3.8.1
-
Then find the settings in conf XML file, opening
-
Find the localRepository, find the location in the figure below, copy the contents in the first red box to the second red box, and copy D: \ environment \ apache-maven-3.8.11 \ Maven repo to the blue box.
1.6 using Maven in idea
-
Create a new project
-
Waiting for initialization
-
The following figure shows success
-
Watch what's in maven's warehouse?
-
maven settings in idea
Note: after the idea project is successfully created, take a look at the maven configuration
-
Here, the configuration and use of Maven in idea are ok!
1.7pom.xml configuration
<?xml version="1.0" encoding="UTF-8"?> <!--Maven Version header file--> <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> <!--Here is the configuration just now GAV--> <groupId>com.song</groupId> <artifactId>java-01-Maven-study</artifactId> <version>1.0-SNAPSHOT</version> <!--Package:Packaging method of the project jar:Java application war:JavaWeb application --> <packaging>war</packaging> <name>java-01-Maven-study Maven Webapp</name> <!-- FIXME change it to the project's website --> <url>http://www.example.com</url> <!--to configure--> <properties> <!--Default build code for the project--> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <!--Compiled version--> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> </properties> <!-- Project dependency--> <dependencies> <!-- Specific dependent jar Package configuration file--> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> </dependencies> <!-- Things for project construction--> <build> <finalName>java-01-Maven-study</finalName> <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> <plugins> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>3.1.0</version> </plugin> <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>3.0.2</version> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.1</version> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>3.2.2</version> </plugin> <plugin> <artifactId>maven-install-plugin</artifactId> <version>2.5.2</version> </plugin> <plugin> <artifactId>maven-deploy-plugin</artifactId> <version>2.8.2</version> </plugin> </plugins> </pluginManagement> </build> </project>