2. Installation and configuration of MAVEN

2. Installation and configuration of MAVEN

1. Official website download: http://maven.apache.org/download.cgi

Insert image description here

2. Unzip the file package

1. Extract apache-maven-3.5.2-bin.zip directly to the specified installation path.

2.apache-maven-3.5.2-src.zip maven source package.

3. Configure environment variables, similar to jdk environment configuration

1. Create the M2_HOME environment variable to point to the maven installation directory.
Insert image description here
2. Append %M2_HOME%\bin to the PATH path.
Insert image description here
3. To debug whether the installation is successful, enter mvn -version in cmd
Insert image description here

4. Configure the local warehouse (jar package directory) to the specified path (*No configuration is required, the default is C drive)

1. In the maven decompression directory, modify the settings.xml file in the conf directory (D:\maven-3.5.2\conf\settings.xml)

Open the settings.xml configuration file, select a local directory as the Maven local repository, and configure
D:\my_maven_local_repository

Insert image description here

5. Configured the image of the central warehouse: (replaced with Alibaba's, which is more stable)

Add the mirror tag under mirrors in the settings.xml file. If you want to use that one, add other comments.

<!-- 阿里云仓库 -->
    <mirror>
        <id>alimaven</id>
        <mirrorOf>central</mirrorOf>
        <name>aliyun maven</name>
        <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
    </mirror>
 
 
    <!-- 中央仓库1 -->
    <mirror>
        <id>repo1</id>
        <mirrorOf>central</mirrorOf>
        <name>Human Readable Name for this Mirror.</name>
        <url>http://repo1.maven.org/maven2/</url>
    </mirror>
 
 
    <!-- 中央仓库2 -->
    <mirror>
        <id>repo2</id>
        <mirrorOf>central</mirrorOf>
        <name>Human Readable Name for this Mirror.</name>
        <url>http://repo2.maven.org/maven2/</url>
    </mirror>

6. Configure the specified JDK version in the Maven configuration file

<profile>    
    <id>jdk-1.8</id>    
     <activation>    
        <activeByDefault>true</activeByDefault>    
        <jdk>1.8</jdk>    
      </activation>    
    <properties>    
        <maven.compiler.source>1.8</maven.compiler.source>    
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> 
    </properties>    
</profile>

[Note] If there is no JDK 1.8 locally, this configuration will not take effect.

7. Configure MAVEN in IDEA

1. First open IDEA and select File - Settings
Insert image description here
2. We can also check some other options
Insert image description here
3. We can update the local warehouse and remote warehouse, so that when adding the coordinates that depend on the jia package in the pom.xml file Good tips come out.

Insert image description here

8. Upload the local jar package to the local Maven warehouse

1) Enter the .jar package into the local warehouse-mvn method

Applicable scene:

The company's private package or the jar package that has not been uploaded to the public warehouse, so Maven cannot get the package, causing the pom to be marked red.

Solutions:

1. First you need to get the jar package, save it to your computer, and record the file path where it is stored.

2. The Maven environment must be installed on the computer, that is, the Maven environment variables are configured. You can use the mvn command (use mvn -v to check whether it is configured. Students who have not configured it can go to Baidu to install and configure it)

3. Use the following command:

mvn install:install-file -Dfile={
    
    jar包所在地址} -DgroupId={
    
    jar包的公司名} -DartifactId={
    
    jar包项目名} -Dversion={
    
    jar包版本} -Dpackaging=jar

  • Dfile: The path of the jar package in the local area
  • DgroupId: groupid of jar package
  • DartifactId: artifactId of the jar package
  • Dversion: version of the jar package
  • Dpackaging: package type

Example:
For example, we have a jar package called ojdbc6-11.2.0.3.jar

There is no remote warehouse for this package, and the pom file is marked red, so we need to get the path of the package, the company name of the package, the project name of the package, and the version of the package

The path of the jar package: the location where the jar package is stored, such as /Users/cheng/Desktop/ojdbc6-11.2.0.3.jar on the desktop

Company name of the jar package: This can be freely used. In order not to confuse the package, you can unzip the jar package and see the folder structure. Here I choose to use com.oracle

The project name of the jar package: According to the jar package name, use ojdbc6

Jar package version: According to the jar package name, if 11.2.0.3 is used
, then I need to enter the following command on the console:

mvn install:install-file -Dfile=/Users/chenghuang/Desktop/ojdbc6-11.2.0.3.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.3 -Dpackaging=jar

Guess you like

Origin blog.csdn.net/m0_49353216/article/details/133387073