Premise:---------------------------------------------------------------------------------------------------------------------- ------
Project:maven
Description:maven is a software project management tool that is based on the Project object Model (POM) that can manage project build, reporting, and documentation through a short description of the information.
--------------------------------------------------------------------------------------------------------------- -----------------------
First, how to build a project using Maven
1. Download and install Maven
Maven_home: "Maven's installation directory"
Path:%maven_home%\bin
2, create a new Pom.xml file, write the corresponding configuration in the file
*
<?xml version= "1.0" encoding= "UTF-8"?>
<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/maven-v4_0_0.xsd" >
<modelVersion>4.0.0</modelVersion>
<groupId>cn.water.maven.hello</groupId>
<artifactId>hello-first</artifactId>
<version>SNAPSHOT-0.0.1</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
* One of the most important element nodes is gav--(groupid,artifactid,version)
Project coordinates
GroupId------------------used to indicate the name of the project
Artifactid---------------the module used to represent the project, it is recommended to use the project name-module name such as:crm-usergroup
VersionId----------------The version number of the project
3, set up the corresponding engineering catalogue, but the strict format is as follows
Pom.xml
Src
Main
Java------------------------Java source code
Resources-------------------Resource directory for source files, (hibernate.cfg.xml,applicationcontext.xml)
Test
Test code for Java------------------------Engineering
Resource catalog files used by Resources-------------------test Engineering
4, execute MVN compile command
* This time maven will download the corresponding jar package (saved in the. M2 folder) from the central repository, but can set the local warehouse
* Set up a local directory to download to the local repository and open the settings.xml file
Find <localRepository>D:/Java/maven</localRepository> inside content can be based on their own want to prevent the place
But here's the file to conf/the setttings under the file.
5,archetype skeleton to build your own project
5.1: Create a new directory to place our project: mkdir 03
5.2: Switch to the newly created 03 directory, execute MVN archetype:generate
5.3: Follow the prompts to build our project
Second, formal access to MAVEN's learning
1,maven can be divided into three departments in general
* Dependent
* Warehouse
* Life cycle and plugins
Three, depend on
1, query for dependent packages
* All dependencies are stored by coordinates (gav-->groupid,artifactid,version)
* There are some online warehouses that provide queries
* What's called transitive dependency
Dependency is a----------that will be passed, but it only works on compile.
If we create a new project, this project is mainly to place PO objects, but using the jar package to hibernate core,
So when we create a new project, we need to rely on one of the previous projects, so we're going to import this project, but at the same time, Hibernate's jar package
will also be imported in the corresponding.
The 1,test scope refers to the scope of the test that is valid and does not use this dependency when compiling and packaging
2,compile scope refers to the compilation scope is valid, when compiling and packaging will be stored in the dependency
3,provided dependencies, which are valid during compilation and testing, are not added when the war package is finally generated, such as,
Serviet-api, because a Web server such as Servlet-api,tomcat already exists, if you re-package back to the conflict
3,runtime is dependent on the runtime and will not be relied upon at compile time.
maven--Software Project management tool (DAY01)