Maven app - install

Clarify what maven can help us do

  1. project build
  2. dependency management
  3. Modular development
  4. code test
  5. Project Information Management
  6. Continuous Integration

maven download and installation

 

1: The windows system decompresses the maven project to the specified directory D:\sof\apache-maven-3.3.3-bin     mven download path ,

The directory structure is as follows


 2: After the decompression is completed, a simple configuration is required before it can be used

Environment variable configuration M2_HOME-> D:\sof\apache-maven-3.3.3-bin

Add ${M2_HOME}\bin to the environment variable path

maven is completed after the above two steps of basic configuration, cmd console input mvn -version to view maven version information

 

maven related configuration files

settings.xml exists in two places:

 1. Installation place: $M2_HOME/conf/settings.xml (global configuration)

 2. User's directory: ${user.home}/.m2/settings.xml (user configuration)

The generation of .m2 can use the mvn command

 

setting related configuration

 

<?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">
        
        Local warehouse directory configuration
	<localRepository>C:\Users\x\.m2\repository</localRepository>

        Remote warehouse authentication information configuration
	<servers>
		<server>
			<id>nexus2</id> corresponds to the warehouse id
			<username>admin</username>
			<password>admin123</password>
		</server>
	</servers>

        Remote warehouse mirror configuration
	<mirrors>
		<mirror>
			<id>external</id>  镜像id
			<mirrorOf>external:*,central</mirrorOf>is mirrored repository id
			<name>Human Readable Name for this Mirror.</name>
			<url>http://xxxx:8081/nexus/content/groups/public/</url>
		</mirror>
	</mirrors>

        warehouse configuration
	<repositories>
			<repository>
				<id>admin</id>  仓库id
				<name>Repositorynexus</name>
				<url>http://xxxx:8081/nexus/content/groups/public/</url>
			</repository>
	</repositories>
         
        Custom zodiac configuration
	<profiles>
		<profile>
			<id>dev</id>  配置ID
			<properties>
				<profiles.active>dev</profiles.active>
				<finalName>web</finalName>
			</properties>
			<repositories>
				<repository>
					<id>admin</id>
					<name>Repositorynexus</name>
					<url>http://xxxx:8081/nexus/content/groups/public/</url>
				</repository>
			</repositories>
		</profile>
		<!--Publish Environment-->
		<profile>
			<id>prod</id> 配置ID
			<properties>
				<profiles.active>dev</profiles.active>
				<finalName>web</finalName>
			</properties>
			<repositories>
				<repository>
					<id>admin</id>
					<name>Repositorynexus</name>
					<url>http://xxxx:8081/nexus/content/groups/public/</url>
				</repository>
			</repositories>
		</profile>
	</profiles>
	
	<activeProfiles>
		<activeProfile>dev</activeProfile> Enable custom zodiac configuration based on ID
	</activeProfiles>

</settings>
 

 Warehouse mirror configuration

<mirrorOf>external:*</mirrorOf> matches all remote repositories not on the local machine (except those using localhost and file:// protocols)

<mirrorOf>*</mirrorOf> matches all remote repositories

<mirrorOf>repo1,repo2</mirrorOf> 对rpo1和repo2进行镜像,使用逗号分隔,rep1的为仓库ID

<mirrorOf>*,!repo2</mirrorOf> 匹配所有远程仓库,repo2除外,使用感叹号将仓库从匹配中排除

 

 

仓库分类

  1. 本地仓库
  2. 远程仓库(私服 中央仓库 其他公共仓库都输入远程仓库)
  •       私服
  •       中央仓库
  (apache-maven-3.5.2\lib -> maven-model-builder-3.5.2.jar -> org\apache\maven\model\pom-4.0.0.xml(超级pom)) 
  <repositories>
    <repository>
      <id>central</id>
      <name>Central Repository</name>
      <url>https://repo.maven.apache.org/maven2</url>
      <layout>default</layout>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
  </repositories>

 

  •       其他公共仓库

 

所有pom(项目对象模型都继承超级pom) 从超级pom中可看出maven约定项目的目录结构如下

 

<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<!-- START SNIPPET: superpom -->
<project>
  <modelVersion>4.0.0</modelVersion>

  <repositories>
    <repository>
      <id>central</id>
      <name>Central Repository</name>
      <url>https://repo.maven.apache.org/maven2</url>
      <layout>default</layout>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
  </repositories>

  <pluginRepositories>
    <pluginRepository>
      <id>central</id>
      <name>Central Repository</name>
      <url>https://repo.maven.apache.org/maven2</url>
      <layout>default</layout>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
    </pluginRepository>
  </pluginRepositories>

  <build>
    <directory>${project.basedir}/target</directory>
    <outputDirectory>${project.build.directory}/classes</outputDirectory>
    <finalName>${project.artifactId}-${project.version}</finalName>
    <testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
    <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
    <scriptSourceDirectory>${project.basedir}/src/main/scripts</scriptSourceDirectory>
    <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
    <resources>
      <resource>
        <directory>${project.basedir}/src/main/resources</directory>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <directory>${project.basedir}/src/test/resources</directory>
      </testResource>
    </testResources>
    <pluginManagement>
      <!-- NOTE: These plugins will be removed from future versions of the super POM -->
      <!-- They are kept for the moment as they are very unlikely to conflict with lifecycle mappings (MNG-4453) -->
      <plugins>
        <plugin>
          <artifactId>maven-antrun-plugin</artifactId>
          <version>1.3</version>
        </plugin>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>2.2-beta-5</version>
        </plugin>
        <plugin>
          <artifactId>maven-dependency-plugin</artifactId>
          <version>2.8</version>
        </plugin>
        <plugin>
          <artifactId>maven-release-plugin</artifactId>
          <version>2.3.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

  <reporting>
    <outputDirectory>${project.build.directory}/site</outputDirectory>
  </reporting>

  <profiles>
    <!-- NOTE: The release profile will be removed from future versions of the super POM -->
    <profile>
      <id>release-profile</id>

      <activation>
        <property>
          <name>performRelease</name>
          <value>true</value>
        </property>
      </activation>

      <build>
        <plugins>
          <plugin>
            <inherited>true</inherited>
            <artifactId>maven-source-plugin</artifactId>
            <executions>
              <execution>
                <id>attach-sources</id>
                <goals>
                  <goal>jar</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <inherited>true</inherited>
            <artifactId>maven-javadoc-plugin</artifactId>
            <executions>
              <execution>
                <id>attach-javadocs</id>
                <goals>
                  <goal>jar</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <inherited>true</inherited>
            <artifactId>maven-deploy-plugin</artifactId>
            <configuration>
              <updateReleaseInfo>true</updateReleaseInfo>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

</project>
<!-- END SNIPPET: superpom -->

 

 

  超级pom中已经默认定义了项目的基本结构

    <directory>${project.basedir}/target</directory> 项目构建后目标的输出目录
    <outputDirectory>${project.build.directory}/classes</outputDirectory>源码目录
    <finalName>${project.artifactId}-${project.version}</finalName>项目名称命名方式
    <testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>测试代码源码目录
    <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>源码目录
    <scriptSourceDirectory>${project.basedir}/src/main/scripts</scriptSourceDirectory>脚本源码目录
    <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>测试代码目录
${project.build.directory} = <directory>${project.basedir}/target</directory>
${project.basedir} = 项目目录

 约定的项目目录结构

src

     main

          java

     test

          java

target

     ${project.artifactId}-${project.version}.jar/war...

     class

     test-class

pom

 

 

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326025792&siteId=291194637