In use maven to build a Spring MVC project before, you need to install on this machine configured Maven .
The machine configuration Maven
First go to Apache official website to download the required maven, attention will need to download bin.tar.gz format, not down to bin.zip or src.tar.zip.
Decompression in their own folder, I placed Users / Yourname / Applications / maven / apache-maven-3.6.1 below
Configuration environment variable
1 source ~/.bash_profile
Add inside
1 export M2_HOME=/Users/lzz/Applications/maven/apache-maven-3.6.1
2 export M2=$M2_HOME/bin
3 export PATH=$M2:$PATH
The path to the directory where you can maven
Then the production order
1 source ~/.bash_profile
Change the default Maven repository
If you do not change the position of the warehouses, the system will automatically generate a folder to store .m2 local warehouse, we changed the default warehouse location management easier
Create a folder in maven repository below
Users/Yourname/Applications/maven/repository
Creating setting.xml: the Users / Yourname / Applications / Maven / setting.xml. In apache-maven-3.6.1 / bin Here there is a setting.xml, our own assigned setting.xml is used to replace it.
Configuration setting.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> 5 6 <pluginGroups /> 7 <proxies /> 8 <servers /> 9 10 <localRepository>/User/lzz/Application/maven/repository</localRepository> 11 12 <mirrors> 13 <mirror> 14 <id>alimaven</id> 15 <mirrorOf>central</mirrorOf> 16 <name>aliyun maven</name> 17 <url>http://maven.aliyun.com/nexus/content/repositories/central/</url> 18 </mirror> 19 <mirror> 20 <id>alimaven</id> 21 <name>aliyun maven</name> 22 <url>http://maven.aliyun.com/nexus/content/groups/public/</url> 23 <mirrorOf>central</mirrorOf> 24 </mirror> 25 <mirror> 26 <id>central</id> 27 <name>Maven Repository Switchboard</name> 28 <url>http://repo1.maven.org/maven2/</url> 29 <mirrorOf>central</mirrorOf> 30 </mirror> 31 <mirror> 32 <id>repo2</id> 33 <mirrorOf>central</mirrorOf> 34 <name>Human Readable Name for this Mirror.</name> 35 <url>http://repo2.maven.org/maven2/</url> 36 </mirror> 37 <mirror> 38 <id>ibiblio</id> 39 <mirrorOf>central</mirrorOf> 40 <name>Human Readable Name for this Mirror.</name> 41 <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url> 42 </mirror> 43 <mirror> 44 <id>jboss-public-repository-group</id> 45 <mirrorOf>central</mirrorOf> 46 <name>JBoss Public Repository Group</name> 47 <url>http://repository.jboss.org/nexus/content/groups/public</url> </48 mirror> 49 <mirror> 50 <id>google-maven-central</id> 51 <name>Google Maven Central</name> 52 <url>https://maven-central.storage.googleapis.com 53 </url> 54 <mirrorOf>central</mirrorOf> 55 </mirror> 56 <!-- 中央仓库在中国的镜像 --> 57 <mirror> 58 <id>maven.net.cn</id> 59 <name>oneof the central mirrors in china</name> 60 <url>http://maven.net.cn/content/groups/public/</url> 61 <mirrorOf>central</mirrorOf> 62 </mirror> 63 </mirrors> 64 </settings>
Configured Maven , the view of the configuration of the maven whether the machine uses JDK version consistent: mvn -v
1 ➜ ~ mvn -v
2 Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-05T03:00:29+08:00)
3 Maven home: /Users/lzz/Applications/maven/apache-maven-3.6.1
4 Java version: 11.0.2, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home
5 Default locale: zh_CN_#Hans, platform encoding: UTF-8
6 OS name: "mac os x", version: "10.14.6", arch: "x86_64", family: "mac"
I use the JDK version 11.0.2. And maven match, the explanation has been configured Maven
In selected IDEA configured Mave
Select Build tools-> Maven in settings. Before we choose a good directory configured Maven, warehouses and setting.xml.
In Build tools-> Maven-> Runner in, JRE environment and select Maven match the version I have here is 11.0.2.
Maven project
Click next, GroupId value of the company name, ArtifactId is the project name.
Continue to click next, where a good selection Maven's home directory, setting file and select the location of our own warehouse location defined. First check to cover the button.
Click next, fill in the project name
Click continue after next, created, IDEA will help us pull the required jar package, so the process of creating the need to maintain the smooth flow of the network, if we had set before pulling jar of sources, such as the use of Ali's source, the process is soon be completed.
Once it got me to jar IDEA to help us complete package, take a look at the initial project structure created out
webapp folder decentralization of some pages, and start the configuration of the project, WEB-INF, configure its entirety below web.xml will project back to him alone will be configured.
I pulled out of the project following main no resource folder, this folder we need to create, and it is set to select the right resource root.
Configuration Environment
First, let's configure project dependencies in pom.xml.
In Maven repository search you want to use the jar package dependencies. It relies on the pom.xml.
1 <dependencies> 2 <dependency> 3 <groupId>junit</groupId> 4 <artifactId>junit</artifactId> 5 <version>4.11</version> 6 <scope>test</scope> 7 </dependency> 8 <!-- https://mvnrepository.com/artifact/org.springframework/spring-beans --> 9 <dependency> 10 <groupId>org.springframework</groupId> 11 <artifactId>spring-beans</artifactId> 12 <version>${springframework.version}</version> 13 </dependency> 14 <!-- spring-context --> 15 <dependency> 16 <groupId>org.springframework</groupId> 17 <artifactId>spring-context</artifactId> 18 <version>${springframework.version}</version> 19 </dependency> 20 21 <!-- Spring MVC + Spring web --> 22 <dependency> 23 <groupId>org.springframework</groupId> 24 <artifactId>spring-web</artifactId> 25 <version>${springframework.version}</version> 26 </dependency> 27 28 <dependency> 29 <groupId>org.springframework</groupId> 30 <artifactId>spring-webmvc</artifactId> 31 <version>${springframework.version}</version> 32 </dependency> 33 34 <!--jdbc --> 35 <dependency> 36 <groupId>org.springframework</groupId> 37 <artifactId>spring-jdbc</artifactId> 38 <version>${springframework.version}</version> 39 </dependency> 40 41 <!-- mybatis --> 42 <dependency> 43 <groupId>org.mybatis</groupId> 44 <artifactId>mybatis</artifactId> 45 <version>3.4.0</version> 46 </dependency> 47 <dependency> 48 <groupId>org.mybatis</groupId> 49 <artifactId>mybatis-spring</artifactId> 50 <version>1.3.0</version> 51 </dependency> 52 53 <!-- druid 数据源的管理 --> 54 <!-- https://mvnrepository.com/artifact/com.alibaba/druid --> 55 <dependency> 56 <groupId>com.alibaba</groupId> 57 <artifactId>druid</artifactId> 58 <version>1.1.12</version> 59 </dependency> 60 61 <!-- mysql -> 62 is < dependency > 63 is < the groupId > MySQL </ the groupId > 64 < the artifactId > MySQL-Connector-Java </ the artifactId > 65 < Version > 5.1.30 </ Version > 66 </ dependency > 67 68 <! - - Lombok, a bunch of notes can be obtained, get, set, toString the methods can be omitted -> 69 < dependency > 70 < the groupId > ORG.projectlombok</groupId> 71 <artifactId>lombok</artifactId> 72 <optional>true</optional> 73 <version>1.18.8</version> 74 </dependency> 75 76 <!-- Jackson 处理json数据 --> 77 <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jsr310 --> 78 <dependency> 79 <groupId>com.fasterxml.jackson.datatype</groupId> 80 <artifactId>jackson-datatype-jsr310</artifactId> 81 <!--jackson-datatype-guava ???? --> 82 <version>2.9.8</version> 83 </dependency> 84 85 </dependencies>