Abstract: Maven notes - June 11, 2021
1. Download and install
1.1 check the version of JDK
JDK version requires version 1.7 or above (detailed description on the official website)
1.2 official website download
Download address of official website (recommended version 3.6.1): https://archive.apache.org/dist/maven/maven-3/3.6.1/binaries/
1.3 unpack the installation package and configure the environment variables (steps: the same as configuring JDK environment variables)
-
Do not appear Chinese or space characters in the path
-
Add MAVEN_HOME to system path
-
Check whether the configuration is successful: cmd → enter the dos window → enter: mvn -v → see the version information, indicating that the configuration is successful
2. Know Maven
2.1 Maven project directory structure
-
Here is the directory structure of maven project in idea, which will be explained in detail later
2.2 important configuration of maven
2.2.1 modify the storage location of local warehouse
2.2.2 change Alibaba image to speed up dependent Download
<mirror> <id>nexus-aliyun</id> <mirrorOf>central</mirrorOf> <name>Nexus aliyun</name> <url>http://maven.aliyun.com/nexus/content/groups/public</url> </mirror>
2.3 understand Maven's common commands
#Note: the following command must be run under Maven project directory, that is, project directory POM The directory where the XML file is located 1. mvn -version:display version information 2. mvn clean:Empty temporary files generated by the project 3. mvn compile:Compile source code,catalog: src/main/java 4. mvn package:Pack Project ,target Directory generation jar or war Other documents 5. mvn test:Execute test cases,catalog: src/test/java/juni 6. mvn install:Copy the packaged items to the local warehouse 7. mvn deploy:Publish the packaged files to the remote and provide dependencies 8. mvn size:Generate relevant websites for the project 9. mvn eclipse:eclipse:Convert project to eclipse project 10.mvn dependency:tree:Print out the dependency tree of the whole project 11.mvn archetype:generate:establish Maven Ordinary java project 12.mvn tomcat8:run:stay tomcat Medium operation web application
3. idea integration Maven
3.1 change maven version
-
File→New Project Settings
-
Build, Execution, Deployment → Build Tools → maven → find the decompression path of the Maven version we downloaded → configuration completed
3.2 creating Maven project
-
New Project → maven → check template → create ordinary Maven project → NEXT
-
Set project name and other information
-
Select Maven version and confirm relevant information
-
⑥ When creating Maven project for the first time, you need to download relevant dependencies, and the waiting time is quite long
-
Manually create a resource directory: resources
3.3 compiling or packaging projects
-
By adding operation commands or packaging and other operations
-
Compile or package through the console
3.4 compilation / packaging is successful, and the target file directory is not automatically generated
-
The first possibility: check whether you want to uncheck Show Excluded Files
-
Other situations: self search
3.5 creating a Web project
-
The basic steps are similar. Check the template. Note: select webapp
-
Creation complete
3.6 modify relevant configurations (find the corresponding location under pom.xml to modify)
-
Modify JDK version
-
Modify Junit test version (the latest version can be viewed in the local warehouse: Repository)
-
Delete unnecessary plug-ins (< pluginmanagement >... < / pluginmanagement >, delete this tag and its contents)
-
Configure server: under < build > tab → < plugins > tab → < plugin ></ Plugin > tag, where the server in Maven project is through POM XML dependency (take Tomcat as an example)
<plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.1</version> <configuration> <port>8080</port> <!--Port number: 8080--> <path>/test</path> <!--External access path--> <uriEncoding>UTF-8</uriEncoding> <!--Character set encoding--> <server>myWebMaven</server> <!--Server name(custom)--> </configuration> </plugin> </plugins>
3.7 starting the server
-
Start the server with Maven command
-
Start in other ways (not detailed here)