MAVEN
Maven is a project management and integration tool developed by Java. Maven Project Object Model (POM), a software project management tool that manages project builds, reports, and documentation with a short description of information. Maven provides developers with a complete build lifecycle framework. It takes almost no time for the development team to automate the basic build configuration of the project because Maven uses a standard directory structure and a default build lifecycle.
Maven’s advantages:
- Automatic build (clean, compile, test, report, package (JAR, WAR), project deployment…)
- Jar package dependency management (automatic package guide according to the configuration in PEM.xml, local repository is not available, find the central repository)
- Contract programming (code is more formal in a canonical format)
An automated build
- Clean up the code: equivalent to running clear
- Auto-compile: This can be done automatically for us (similar to executing javac to generate class files)
- Complete the test: Implement the test function
- Report generation: it can be more convenient to achieve project management
- Packaging: Jar package for common projects, war package for Web projects
- Project deployment: A single command MVN jetty:run can be used to deploy the project
Note: To use the jetty:run command, you must have a plugin. (Maven has a lot of commands, but you don’t want to use them. Some commands require plugins.)
Jar package dependency management
When we need to import a functional JAR that depends on other JARS. Maven solves this problem perfectly. You just import the package and it will automatically import the dependency packages for you.
Note: Using Maven packages requires XML configuration (POM.xml)
Contract programming
Agree on the basic structure of the project. The structure of Maven projects must be the structure required by Maven. This kind of contract programming makes the code structure uniform and makes multi-person (multi-team) development easier.
Projects with the same Maven structure can run in a variety of different development tools.
Maven installation
Before installing Maven, you need to configure JDK and Maven environment variables JAVA_HOME, MAVEN_HOME, and corresponding path
Configuring a Local Warehouse
- Prepare local warehouse
- Copy settings. XML from maven installation directory conf folder to drive C. m2 and delete the default repository
- C: \ Users \ Administrator/m2 / Settings. The XML, the XML file configuration local repository path, under the Settings TAB
Configuring Ali Mirror
In maven’s settings. XML file, add the mirrors node as follows:
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
Copy the code
Maven commands
Open the CMD command line and enter the Hello project root directory
- Run MVN compile to compile
- MVN clean clean
- MVN clean compile
- MVN test Test (run, fail, error)
- MVN package packaging
- MVN source:jar
- MVN site generates a website (document)
- MVN install types the JARS into the local repository
- MVN Eclipse: Eclipse requires two files to generate Eclipse
- MVN package-dmaven.test. skip=true Does not run the command of the test case during packaging
Basic configuration of POM.xml
<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>
<! -- group ID: package name -->
<groupId>cn.itsource.maven</groupId>
<! -- module name: same as project name -->
<artifactId>Hello</artifactId>
<! Bug RELEASE -- stable version -->
<version>0.0.1 - the SNAPSHOT</version>
<! -- Project name -->
<name>hello</name>
<! -- JAR file dependencies -->
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<! SRC /test/ Java -->
<scope>test</scope>
</dependency>
</dependencies>
</project>
Copy the code
Find the maven packages
What package do YOU need to import, search online and copy it to POM.xml
Address: mvnrepository.com/