windows安装maven以及配置

下载maven

还没有下载的小伙伴请移步maven官网下载。如下图所示:
在这里插入图片描述
请按照自己的系统下载不同的版本:
在这里插入图片描述
解压下载好的文件:
在这里插入图片描述

配置maven环境变量

  • 右击此电脑->属性->高级系统设置->环境变量->系统变量
  • 配置MAVEN_HOME。在系统变量中新建,变量名MAVEN_HOME,变量值,maven文件夹路径。

在这里插入图片描述

  • 配置path。找到path系统变量->编辑->新建,输入“%MAVEN_HOME%\bin”。
    在这里插入图片描述
  • 验证maven是否安装成功。
    运行命令窗口,输入mvn -v,如下图所示即为安装成功:
    在这里插入图片描述

配置setting文件

打开maven解压目录->conf->找到setting文件

  • 配置本地仓库
    在这里插入图片描述

  • 配置远程仓库
    在这里插入图片描述

  • 配置JDK
    在这里插入图片描述

  • 配置好的setting文件

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
  <!-- localRepository	
  本地存储库maven的路径将用于存储工件。  
  Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository> -->
  <localRepository>D:\Software\Java\Environment\Maven\Repository</localRepository>

  <!-- interactiveMode
   |这将决定maven在需要输入时是否会提示您。如果设为false,Maven将使用一个合理的默认值,可能基于其他设置问题中的参数。
   | Default: true
  <interactiveMode>true</interactiveMode>-->
	<interactiveMode>true</interactiveMode>
  <!-- offline
   |确定maven在执行构建时是否应该尝试连接到网络。这将对工件下载、工件部署和其他方面产生影响。
   | Default: false
  <offline>false</offline> -->
  <offline>false</offline>

  <!-- pluginGroups
   | 这是一个额外的组标识符列表,当解析插件的前缀时,将会被搜索。当调用像“mvn前缀:目标”这样的命令行时。
   Maven将自动添加组标识符“org.apache.maven。插件”和“org.codehaus。Mojo”,如果这些还没有包含在列表中。-->
  <pluginGroups>
    <!-- pluginGroup 
	指定用于插件查找的进一步组标识符。
    <pluginGroup>com.your.plugins</pluginGroup> -->
  </pluginGroups>

  <!-- proxies
   | 这是可在此机器上用于连接到网络的代理列表。除非另有指定(通过系统属性或命令行开关),第一个代理将使用此列表中标记为活动的|规范。
   |-->
  <proxies>
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     |一个代理的规范,用于连接到网络。
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>

  <!-- servers
   | 这是一个身份验证配置文件列表,由系统中使用的服务器id键入。身份验证配置文件可以在maven必须连接到远程服务器时使用。-->
  <servers>
    <!-- server
    指定连接到特定服务器时要使用的身份验证信息(由是系统中唯一的名称(由下面的'id'属性引用)。
	注意:您应该指定用户名/密码或privateKey/passphrase,因为这些对是一起使用。
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->
    <!-- 另一个示例,使用密钥进行身份验证。
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
  </servers>

  <!-- mirrors
   | 这是从远程存储库下载工件时使用的镜像列表。它的工作方式是这样的:POM可以声明一个存储库来解决某些工件。
   然而,这个存储库有时可能会遇到流量过大的问题,因此人们已经进行了镜像把它送到几个地方。
	那个存储库定义将有一个唯一的id,所以我们可以为它创建一个镜像引用库,用作备用下载站点。镜像站点将是首选该存储库的|服务器。-->
  <mirrors>
    <!-- mirror
     |指定要使用的存储库镜像站点,而不是给定的存储库。该镜像服务的存储库具有与该镜像的mirrorOf元素相匹配的ID。id用于继承和直接查找目的,并且在整个镜像集上必须是唯一的。-->
    <mirror>
        <id>alimaven-central</id>
        <mirrorOf>central</mirrorOf>
		<name>aliyun maven</name>
		<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
	</mirror>
	<mirror>
		<id>jboss-public-repository-group</id>
		<mirrorOf>central</mirrorOf>
		<name>JBoss Public Repository Group</name>
		<url>http://repository.jboss.org/nexus/content/groups/public</url>
	</mirror>
  </mirrors>

  <!-- profiles
   这是一个配置文件列表,可以用多种方式激活,也可以修改构建过程。在settings.xml中提供的配置文件旨在提供本地机器-特定的路径和存储库位置,它们允许构建在本地环境中工作。
	例如,如果你有一个集成测试插件——像cactus——它需要知道在哪里如果您已经安装了Tomcat实例,您可以在这里提供一个变量,以便该变量是在配置cactus插件的构建过程中取消对|的引用。
	如上所述,可以通过多种方式激活概要文件。一种方式——activeProfiles本文档的|部分(settings.xml) -将在后面讨论。另一种方法是
	依赖于系统属性的检测,要么匹配属性的特定值,或者仅仅是测试它的存在。配置文件也可以通过JDK版本前缀激活,其中|的值'1.4'可能会在JDK版本'1.4.2_07'上执行构建时激活配置文件。
	最后,可以直接从命令行指定活动概要文件列表。注意:对于在settings.xml中定义的概要文件,您被限制只能指定工件库、插件库和自由形式的属性可以用作配置在POM中插件的|变量。
   |-->
  <profiles>
    <!-- profile
     | Specifies a set of introductions to the build process, to be activated using one or more of the
     | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
     | or the command line, profiles have to have an ID that is unique.
     |
     | An encouraged best practice for profile identification is to use a consistent naming convention
     | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
     | This will make it more intuitive to understand what the set of introduced profiles is attempting
     | to accomplish, particularly when you only have a list of profile id's for debug.
     |
     | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
	 
	 属性的一个或多个来激活构建流程的引入集上面描述的|机制。用于继承目的,并通过激活配置文件或命令行,配置文件必须具有唯一的ID。
	一个被鼓励的概要文件标识的最佳实践是使用一致的命名约定配置文件,如'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett'等
	这将使它更直观地理解引入的配置文件集正在尝试什么,特别是当您只有一个配置文件id的列表用于调试时。
	这个配置示例使用JDK版本来触发激活,并提供了一个特定于JDK的回购。
    <profile>
      <id>jdk-1.4</id>

      <activation>
        <jdk>1.4</jdk>
      </activation>

      <repositories>
        <repository>
          <id>jdk14</id>
          <name>Repository for JDK 1.4 builds</name>
          <url>http://www.myhost.com/maven/jdk14</url>
          <layout>default</layout>
          <snapshotPolicy>always</snapshotPolicy>
        </repository>
      </repositories>
    </profile>
    -->

    <!--
     | Here is another profile, activated by the system property 'target-env' with a value of 'dev',
     | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
     | might hypothetically look like:
	 下面是另一个配置文件,由系统属性'target-env'激活,值为'dev',它提供了Tomcat实例的特定路径。要使用这个,你的插件配置假设|看起来像:
	 下面是另一个配置文件,由系统属性'target-env'激活,值为'dev',它提供了Tomcat实例的特定路径。要使用这个,你的插件配置假设|看起来像:
     |
     | ...
     | <plugin>
     |   <groupId>org.myco.myplugins</groupId>
     |   <artifactId>myplugin</artifactId>
     |
     |   <configuration>
     |     <tomcatLocation>${tomcatPath}</tomcatLocation>
     |   </configuration>
     | </plugin>
     | ...
     |
     | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
     |       anything, you could just leave off the <value/> inside the activation-property.
     |注意:如果你只是想注入这个配置,每当有人将'target-env'设置为任何东西,你可以只在激活属性中离开。
    <profile>
      <id>env-dev</id>

      <activation>
        <property>
          <name>target-env</name>
          <value>dev</value>
        </property>
      </activation>

      <properties>
        <tomcatPath>/path/to/tomcat/instance</tomcatPath>
      </properties>
    </profile>
    -->
	
	<profile>
		<id>jdk18</id>
		<activation>
			<jdk>1.8</jdk>
			<activeByDefault>true</activeByDefault>
		</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>

  </profiles>

  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |所有构建都处于活动状态的概要文件列表。
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
</settings>

本文为原创文章,如有错误,请指教。


版权声明:本文为weixin_46015796原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。