程序员开发实例大全宝库

网站首页 > 编程文章 正文

搭建Maven环境基础版(mavenssm项目搭建)

zazugpt 2024-09-10 23:33:53 编程文章 23 ℃ 0 评论

一、简介

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

二、系统需求

  • Java SE Development Kit 7

  • Maven 3.3.9

三、下载压缩包

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

https://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

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表