maven 环境搭建(搭建Maven环境基础版)

一、简介在这篇文章中,笔者将介绍如何在windows下搭建Maven环境,接下来我们就来聊聊关于maven 环境搭建?以下内容大家不妨参考一二希望能帮到您!

maven 环境搭建(搭建Maven环境基础版)

maven 环境搭建

一、简介

在这篇文章中,笔者将介绍如何在windows下搭建Maven环境。

二、系统需求

    Java SE Development Kit 7

    Maven 3.3.9

    三、下载压缩包

    Maven官网下载压缩包,即:apache-maven-3.3.9-bin.zip

    http://archive.apache.org/dist/maven/maven-3/3.3.9/

    四、解压压缩包

    建议将apache-maven-3.3.9-bin.zip解压至某盘符的根目录下,尽量不要放入中文或者包含其它特殊字符的目录中,笔者将其解压至D:\maven3.3.9。

    五、配置环境变量

    通过点击“控制面板\系统和安全\系统\高级\环境变量\系统变量”的path变量添加如下路径:D:\maven3.3.9\bin

    打开windows的命令行窗口,输入以下代码:

    C:\Users\DHC>mvn -v Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47 08:00) Maven home: D:\maven3.3.9 Java version: 1.7.0_80, vendor: Oracle Corporation Java home: D:\Java\jdk1.7.0_80\jre Default locale: zh_CN, platform encoding: GBK OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"

    若出现上述结果,则证明环境变量配置成功(注:需要前置条件为已经配置好JDK环境)。

    六、配置maven其它内容

    1. 配置Maven本地仓库位置

    在Maven目录中创建空目录,如:D:\maven3.3.9\repo

    打开文件D:\maven3.3.9\conf\settings.xml修改本地仓库位置

    <!-- localRepository | The path to the local repository maven will use to store artifacts. | | Default: ${user.home}/.m2/repository <localRepository>/path/to/local/repo</localRepository> --> <!--将下面这行修改自定义的本地仓库位置即可 --> <localRepository>D:\maven3.3.9\repo</localRepository>

    2. 配置Maven镜像站点

    打开文件D:\maven3.3.9\conf\settings.xml修改镜像

    <!-- mirrors | This is a list of mirrors to be used in downloading artifacts from remote repositories. | | It works like this: a POM may declare a repository to use in resolving certain artifacts. | However, this repository may have problems with heavy traffic at times, so people have mirrored | it to several places. | | That repository definition will have a unique id, so we can create a mirror reference for that | repository, to be used as an alternate download site. The mirror site will be the preferred | server for that repository. |--> <mirrors> <!-- 这里可以添加多组镜像,以下这组添加的是阿里镜像站点 --> <mirror> <id>nexus-aliyun</id> <mirrorOf>*</mirrorOf> <name>Nexus aliyun</name> <url>http://maven.aliyun.com/nexus/content/groups/public</url> </mirror> </mirrors>

    2. 配置Maven多组文件列表

    <!-- profiles | This is a list of profiles which can be activated in a variety of ways, and which can modify | the build process. profiles provided in the settings.xml are intended to provide local machine- | specific paths and repository locations which allow the build to work in the local environment. | | For example, if you have an integration testing plugin - like cactus - that needs to know where | your Tomcat instance is installed, you can provide a variable here such that the variable is | dereferenced during the build process to configure the cactus plugin. | | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles | section of this document (settings.xml) - will be discussed later. Another way essentially | relies on the detection of a system property, either matching a particular value for the property, | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'. | Finally, the list of active profiles can be specified directly from the command line. | | |--> <!-- JDK7环境 --> <profiles> <profile> <id>jdk-1.7</id> <activation> <activeByDefault>true</activeByDefault> <jdk>1.7</jdk> </activation> <properties> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> <maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion> </properties> </profile> </profiles>

    七、总结

    本文简述了搭建Maven环境,可以在IDE(集成开发环境)中添加Maven相关配置。

    可通过如下命令查询搭建的环境是否成功(详细内容请查看笔者下篇文章):

    mvn archetype:generate -DgroupId=com.dhc.simpleweb -DartifactId=simple-webapp -Dpackage=com.dhc.simpleweb -DarchetypeArtifactId=maven-archetype-webapp -Dversion=1.0-SNAPSHOT -DinteractiveMode=false

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com

    分享
    投诉
    首页