Learn maven, just read this one! ! !

Maven repository***

  • (1) What is a Maven warehouse
    " "1 The warehouse is where the jar packages and plugins used by the project are stored
    " "2 Warehouse classification:
  • Central warehouse: a server that stores all commonly used jars, open to the outside world, maintained by a professional team, address: http://repo1.maven.org/maven2/ (Maven)
  • Remote warehouse (private service): Generally, the enterprise puts the core jar package on its own server (Alibaba Cloud mirroring)
  • Local warehouse: jar包和插件stored locally (that is, a folder)

Insert picture description here

The coordinates of the Maven warehouse***

  • (1) What are the coordinates of the warehouse?
    There are many jar packages in the warehouse. If we find the jar packages we need, we need to set an identifier for each jar package, namely the coordinates
  • (2) The composition of the coordinates:
    groupId: generally the reverse of the company's domain name: com.baidu, com.alibaba
    artifactId: the name of the module project: day13_maven
    version: version: 1.0.1-SNAPSHOT
  • (3) Use the jar package
    to configure in the pom.xml file of the project:
    Insert picture description here

Maven installation and use***

》》1: Unzip the Maven archive
Insert picture description here

""2: Unzip the local warehouse to the Maven folder
""3: Configure the local warehouse
In the unzipped directory, set: conf/settings.xml The local warehouse path is
at line 55: D:\develop\apache-maven-3.5.2 \repository

<localRepository>C:/202009/maven/apache-maven-3.3.9-bin/apache-maven-3.3.9/repository</localRepository>

》》4: Configure the remote warehouse (private server)
and add it to the label on line 159

   <mirror>  
   	<id>nexus-aliyun</id>  
   	<mirrorOf>central</mirrorOf>    
   	<name>Nexus aliyun</name>  
   	<url>http://maven.aliyun.com/nexus/content/groups/public</url>  
   </mirror> 

》》5: Set the Maven environment variable
1) Set MAVEN_HOME to be the path where your maven is located
2) Set the Path environment variable: %MAVEN_HOME%\bin
》》6: Test
After opening DOS: mvn -v version information can appear

Maven's idea configuration***

Insert picture description here

  • (1) Common configuration
    File —>settings —>Search maven —>Specify maven directory, configuration file path, local warehouse path
    Insert picture description here

Set VM options in MavenRunner as: -DarchetypeCatalog=internal

  • (2) Default configuration:
    File—>other setting—>Default Settings—>Search Maven—>Specify maven directory, configuration file path, local warehouse path
    File—>other setting—>Default Settings—>Search for Maven—>Maven Runner—>Set VM optionsto:-DarchetypeCatalog=internal
    Insert picture description here

Maven creates a JavaSe project

  • (1) How to create a JavaSE module in Maven
    " "1 File ----new Project ----> check create from archetype —> select: xxxx.quickstart
    "" 2 Specify a coordinate for the project to be created currently, because I am this The project can also be packaged into a package and released to the warehouse in the future, you must specify 坐标
    》》3 After creating the project, be sure to click on Event-Log in the lower right corner: Import Changes Enable Auto-Import, which can automatically import the jar package from the warehouse

Maven creates JavaWeb project***

(1) How to create a JavaWeb module in Maven?
》》1 File ----new Module ---->Check create from archetype
》》2 Select: xxxx.quickstart The third option below: xxx.webapp
》》3 Set the module name: day11_01_web

Introduction to Maven's web project directory***

(1) Directory
Insert picture description here

Create multiple web projects in Project***

》》1 Create Project and select quickstart (choose to use maven template)
》》2 Select Project, then new Module select webapp

Insert picture description here

The pom.xml file of the Maven project***

pom.xml file

  • (1) Jar package dependency
    If we need to use a jar, we only need to configure it in pom.xml
    (2) Plug-in

Maven project commands

  • (1) Maven comes with some commands for project management:
    clean: clear the project compilation files, delete the target folder under the project
    compile: recompile the project, generate the target folder
    package under the project : change the current The project is marked as the war/jar package under the target folder, and the war package can finally be published on the Linux server
    install: publish the current project to the local warehouse
    test: execute the test program

Maven creates Servlet

(1) Creating Servlet before does not need to guide jar, because we created a javaEE project
(2) Maven creates Servlet need to guide jar and
develop a Servlet
"1: Depend on servlet jar
" 2: Create Servlet

 <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <scope>provided</scope>
    </dependency>

Guess you like

Origin blog.csdn.net/qq_37924905/article/details/108739731
Recommended