Maven download and basic configuration

Maven

Why should I learn this technology?

  1. In Java web, we need to use a large number of jar packages, which we import manually;

  2. How can we make something automatically import and configure this jar package for us

    Thus, maven was born

  3. The advantage of maven is that it will help you import other jar packages that this jar package depends on.

1.1Maven project architecture management tool

We are currently used to facilitate the import of jar packages!

Maven's core idea: Convention is greater than configuration

  • There are constraints. Don't break them.

Maven will specify how you write our Java code, which must be in accordance with this specification

1.2 download Maven

After downloading, unzip it;

1.3 configuring environment variables

In our system environment variables

Configure the following configurations:

  • M2_ bin directory under home maven

  • MAVEN_HOME maven directory

  • Configure Maven in the path of the system_ HOME

 

Test whether Maven is installed successfully and ensure that the configuration must be completed!

1.4 Alibaba cloud image

  • Mirroring: mirrors

    • Function: speed up download

  • Alibaba cloud image is recommended in China

  • Configuring alicloud images

    1. Find the settings in conf under D:\Environment\apache-maven-3.8.1 XML, opening

    2. Put the following code into the settings of the following picture XML, find < mirrors > < / mirrors >, and put them in the middle, as shown in the following picture.

<mirror>
    <id>nexus-aliyun</id>  
    <mirrorOf>*,!jeecg,!jeecg-snapshots</mirrorOf>  
    <name>Nexus aliyun</name>  
    <url>http://maven.aliyun.com/nexus/content/groups/public</url> 
</mirror>

1.5 local warehouse

Local warehouse, remote warehouse;

Set up a local repository: localRepository

  1. Create a new Maven repo folder under D:\Environment\apache-maven-3.8.1

  2. Then find the settings in conf XML file, opening

  3. Find the localRepository, find the location in the figure below, copy the contents in the first red box to the second red box, and copy D: \ environment \ apache-maven-3.8.11 \ Maven repo to the blue box.

1.6 using Maven in idea

  1. Create a new project

       

     

     

     

  2. Waiting for initialization

  3. The following figure shows success

     

  4. Watch what's in maven's warehouse?

  5. maven settings in idea

    Note: after the idea project is successfully created, take a look at the maven configuration

     

  6. Here, the configuration and use of Maven in idea are ok!

1.7pom.xml configuration

<?xml version="1.0" encoding="UTF-8"?>
<!--Maven Version header file-->
<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>
<!--Here is the configuration just now GAV-->
  <groupId>com.song</groupId>
  <artifactId>java-01-Maven-study</artifactId>
  <version>1.0-SNAPSHOT</version>
  <!--Package:Packaging method of the project
  jar:Java application
  war:JavaWeb application
  -->
  <packaging>war</packaging>
​
  <name>java-01-Maven-study Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>
​
  <!--to configure-->
  <properties>
    <!--Default build code for the project-->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <!--Compiled version-->
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>
​
<!--  Project dependency-->
  <dependencies>
<!--    Specific dependent jar Package configuration file-->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
​
​
<!--  Things for project construction-->
  <build>
    <finalName>java-01-Maven-study</finalName>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>
​

Keywords: Java Maven

Added by kampbell411 on Fri, 14 Jan 2022 12:35:22 +0200