Recently I have been learning Maven, which I haven't used before, but I don't always have a deep understanding. Now I want to share my recent learning experience and Maven's usage, in the hope of helping beginners.
1. First, there's the saying that Maven is a popular dot found online:
Maven is a project building and management tool that provides methods to help manage builds, documents, reports, dependencies, scms, publishing, and distribution. You can easily compile code, manage dependencies, manage binary libraries, and so on.
The benefits of maven are standardization, automation, efficiency, and scalability of project processes
maven itself and its plug-ins also provide access to code review reports, unit test coverage, continuous integration, and more.
As I understand it, most of the current projects use Maven for version management of Jar packages.
Maven's aggregation project management is particularly convenient, as when a large project contains many modules, each person develops their own modules and can use the Maven aggregation project for version management.
2. Tools used:
1. Go to the website to download apache-maven-3.1.1 (Maven must be understood as a repository for Jar packages.)
2.repository (this is the local Jar package repository, if not, you will download Jar packages from the Maven server every time you use them in your project; it is best to find someone else's repository and bring them back so that each time you use Jar packages, you will first find them from the local repository, then automatically download them from the Maven server to the local repository, and copy them to the project. Repository can be configured in Maven's set.xml, which will follow)
3.nexus-2.14.2-01 (nexus is a private service, equivalent to Maven built on company servers). Because many companies restrict external network connections, you can't download Jar packages from Maven's official network without private service, so you can set up nexus on machines that can connect to the external network, and other local area network machines can download Jar packages directly from nexus)
3. Build Maven
Place apache-maven-3.1.1 and repository in D:maven.
Maven's core configuration file is settings.xml. Here's my finished configuration file.
<?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"> <localRepository>D:maven epository</localRepository> <pluginGroups> </pluginGroups> <proxies> </proxies> <servers> <server> <id>releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>snapshots</id> <username>admin</username> <password>admin123</password> </server> </servers> <mirrors> <mirror> <id>nexus-repos</id> <mirrorOf>*</mirrorOf> <name>Team Nexus Repository</name> <url>http://192.168.8.79:8081/nexus/content/groups/public/</url> </mirror> </mirrors> <profiles> <profile> <id>jdk-1.7</id> <activation> <activeByDefault>true</activeByDefault> <jdk>1.7</jdk> </activation> <properties> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> <maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion> </properties> </profile> </profiles> </settings>
Note the following modifications:
1. Configure the local repository to point to the repository unzipped location:
<localRepository>D:Program Files epository epository</localRepository>
2. Add a private service configuration to the Mirrors tag to point to the nexus private service on the company server
<mirror> <id>nexus-repos</id> <mirrorOf>*</mirrorOf> <name>Team Nexus Repository</name> <url>http://192.168.3.100:8099/nexus/content/groups/public/</url> </mirror>
3. Open myEclipse -> windows -> perferences to search for maven as follows
4.Installations -> add Find the directory that apache-maven-3.1.1 unzipped - OK
5.User settings -> browse found the modified settings in 2. XML text -> update settings -> reindex -> apply
6.windows -> show View -> other finds Maven repositories and sees the following figure to prove the configuration is complete
4. Create a Maven Project
1. Create a Maven Project in MyEclipse
2. Turn a Maven project into a Web project
Project Right-click Properties
The project structure becomes this, a standard web project
3. Core of the Maven project: pom.xml
A pom is a project object Model.
The POM is an XML and is the basis of maven's work. When executing a program, Maven reads pom.xml from the project root directory to get the required configuration information.
The pom file contains information about the project and the configuration information required for the maven build project, usually including project information (such as version, members), project dependencies, plug-ins and goal s, build options, and so on.
The pom.xml for the new Maven Web project above is as follows:
<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.demo</groupId> <artifactId>maven-web</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <build/> </project>
If you want to reference slf4j-1.7.7, add the following paragraph to 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> <groupId>com.demo</groupId> <artifactId>maven-web</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <build/> <dependencies> <dependency> <groupId>com.slf4j</groupId> <artifactId>slf4j</artifactId> <version>1.7.7</version> </dependency> </dependencies> </project>
Then you can compile it, pom. Right-click Run As -> Maven install on XML
Open the target directory:
The red ones are the war packages built by the project; Blue is the jar package you wrote in pom.xml that you want to import
The contents of maven-web-0.0.1-SNAPSHOT and war packages are the same and can be run under Tomcat: