当前位置:   article > 正文

Maven安装和配置及STS配置Maven&IDEA配置Maven_maven核心程序的安装和本地仓库的必要设置

maven核心程序的安装和本地仓库的必要设置

1.maven环境搭建

1.1 maven下载和修改配置

1.1.1.首先登陆官方网站进行下载:Maven – Download Apache Maven

1.1.2.将下载的压缩包解压”apache-maven-版本-bin.zip”到D盘(解压磁盘目录最好不要包含中文、特殊符号和空格的文件夹下)

路径如下:D:\Program Files\apache-maven-3.6.0

 

1.1.3.在 maven 解压目录下,建立 repository 本地仓库目录

1.1.4 系统环境变量中配合mvn执行路径

变量名:MAVEN_HOME=D:\Program Files\apache-maven-3.6.0

变量名:Path=;%MAVEN_HOME%\bin

1.1.5.修改maven的核心配置,打开maven安装目录下conf/settings.xml

  1. <!--设定本地仓库的路径-->
  2. <localRepository>D:\Program Files\apache-maven-3.6.0\repository</localRepository>

 

1.1.5.仓库设定为阿里云的仓库(D:\Program Files\apache-maven-3.6.0\conf\settings.xml  配置文件原代码如下,根据自己安装maven来决定配置文件的路径 )

   maven 阿里云 地址  https://maven.aliyun.com/nexus/content/groups/public/

 

  1. <mirror>
  2. <id>aliyunmaven</id>
  3. <mirrorOf>*</mirrorOf>
  4. <name>aliyun maven</name>
  5. <url>https://maven.aliyun.com/repository/public</url>
  6. </mirror>

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one
  4. or more contributor license agreements. See the NOTICE file
  5. distributed with this work for additional information
  6. regarding copyright ownership. The ASF licenses this file
  7. to you under the Apache License, Version 2.0 (the
  8. "License"); you may not use this file except in compliance
  9. with the License. You may obtain a copy of the License at
  10. http://www.apache.org/licenses/LICENSE-2.0
  11. Unless required by applicable law or agreed to in writing,
  12. software distributed under the License is distributed on an
  13. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. KIND, either express or implied. See the License for the
  15. specific language governing permissions and limitations
  16. under the License.
  17. -->
  18. <!--
  19. | This is the configuration file for Maven. It can be specified at two levels:
  20. |
  21. | 1. User Level. This settings.xml file provides configuration for a single user,
  22. | and is normally provided in ${user.home}/.m2/settings.xml.
  23. |
  24. | NOTE: This location can be overridden with the CLI option:
  25. |
  26. | -s /path/to/user/settings.xml
  27. |
  28. | 2. Global Level. This settings.xml file provides configuration for all Maven
  29. | users on a machine (assuming they're all using the same Maven
  30. | installation). It's normally provided in
  31. | ${maven.conf}/settings.xml.
  32. |
  33. | NOTE: This location can be overridden with the CLI option:
  34. |
  35. | -gs /path/to/global/settings.xml
  36. |
  37. | The sections in this sample file are intended to give you a running start at
  38. | getting the most out of your Maven installation. Where appropriate, the default
  39. | values (values used when the setting is not specified) are provided.
  40. |
  41. |-->
  42. <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  43. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  44. xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  45. <!-- localRepository
  46. | The path to the local repository maven will use to store artifacts.
  47. |
  48. | Default: ${user.home}/.m2/repository
  49. <localRepository>/path/to/local/repo</localRepository>
  50. -->
  51. <!--设定本地仓库的路径-->
  52. <localRepository>D:\Program Files\apache-maven-3.6.0\repository</localRepository>
  53. <!-- interactiveMode
  54. | This will determine whether maven prompts you when it needs input. If set to false,
  55. | maven will use a sensible default value, perhaps based on some other setting, for
  56. | the parameter in question.
  57. |
  58. | Default: true
  59. <interactiveMode>true</interactiveMode>
  60. -->
  61. <!-- offline
  62. | Determines whether maven should attempt to connect to the network when executing a build.
  63. | This will have an effect on artifact downloads, artifact deployment, and others.
  64. |
  65. | Default: false
  66. <offline>false</offline>
  67. -->
  68. <!-- pluginGroups
  69. | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
  70. | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
  71. | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
  72. |-->
  73. <pluginGroups>
  74. <!-- pluginGroup
  75. | Specifies a further group identifier to use for plugin lookup.
  76. <pluginGroup>com.your.plugins</pluginGroup>
  77. -->
  78. </pluginGroups>
  79. <!-- proxies
  80. | This is a list of proxies which can be used on this machine to connect to the network.
  81. | Unless otherwise specified (by system property or command-line switch), the first proxy
  82. | specification in this list marked as active will be used.
  83. |-->
  84. <proxies>
  85. <!-- proxy
  86. | Specification for one proxy, to be used in connecting to the network.
  87. |
  88. <proxy>
  89. <id>optional</id>
  90. <active>true</active>
  91. <protocol>http</protocol>
  92. <username>proxyuser</username>
  93. <password>proxypass</password>
  94. <host>proxy.host.net</host>
  95. <port>80</port>
  96. <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
  97. </proxy>
  98. -->
  99. </proxies>
  100. <!-- servers
  101. | This is a list of authentication profiles, keyed by the server-id used within the system.
  102. | Authentication profiles can be used whenever maven must make a connection to a remote server.
  103. |-->
  104. <servers>
  105. <!-- server
  106. | Specifies the authentication information to use when connecting to a particular server, identified by
  107. | a unique name within the system (referred to by the 'id' attribute below).
  108. |
  109. | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
  110. | used together.
  111. |
  112. <server>
  113. <id>deploymentRepo</id>
  114. <username>repouser</username>
  115. <password>repopwd</password>
  116. </server>
  117. -->
  118. <!-- Another sample, using keys to authenticate.
  119. <server>
  120. <id>siteServer</id>
  121. <privateKey>/path/to/private/key</privateKey>
  122. <passphrase>optional; leave empty if not used.</passphrase>
  123. </server>
  124. -->
  125. </servers>
  126. <!-- mirrors
  127. | This is a list of mirrors to be used in downloading artifacts from remote repositories.
  128. |
  129. | It works like this: a POM may declare a repository to use in resolving certain artifacts.
  130. | However, this repository may have problems with heavy traffic at times, so people have mirrored
  131. | it to several places.
  132. |
  133. | That repository definition will have a unique id, so we can create a mirror reference for that
  134. | repository, to be used as an alternate download site. The mirror site will be the preferred
  135. | server for that repository.
  136. |-->
  137. <mirrors>
  138. <!-- mirror
  139. | Specifies a repository mirror site to use instead of a given repository. The repository that
  140. | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
  141. | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
  142. |
  143. <mirror>
  144. <id>mirrorId</id>
  145. <mirrorOf>repositoryId</mirrorOf>
  146. <name>Human Readable Name for this Mirror.</name>
  147. <url>http://my.repository.com/repo/path</url>
  148. </mirror>
  149. -->
  150. <!--设定中央仓库为阿里云-->
  151. <mirror>
  152. <id>alimaven</id>
  153. <name>aliyun maven</name>
  154. <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
  155. <mirrorOf>central</mirrorOf>
  156. </mirror>
  157. </mirrors>
  158. <!-- profiles
  159. | This is a list of profiles which can be activated in a variety of ways, and which can modify
  160. | the build process. Profiles provided in the settings.xml are intended to provide local machine-
  161. | specific paths and repository locations which allow the build to work in the local environment.
  162. |
  163. | For example, if you have an integration testing plugin - like cactus - that needs to know where
  164. | your Tomcat instance is installed, you can provide a variable here such that the variable is
  165. | dereferenced during the build process to configure the cactus plugin.
  166. |
  167. | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
  168. | section of this document (settings.xml) - will be discussed later. Another way essentially
  169. | relies on the detection of a system property, either matching a particular value for the property,
  170. | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
  171. | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
  172. | Finally, the list of active profiles can be specified directly from the command line.
  173. |
  174. | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
  175. | repositories, plugin repositories, and free-form properties to be used as configuration
  176. | variables for plugins in the POM.
  177. |
  178. |-->
  179. <profiles>
  180. <!-- profile
  181. | Specifies a set of introductions to the build process, to be activated using one or more of the
  182. | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
  183. | or the command line, profiles have to have an ID that is unique.
  184. |
  185. | An encouraged best practice for profile identification is to use a consistent naming convention
  186. | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
  187. | This will make it more intuitive to understand what the set of introduced profiles is attempting
  188. | to accomplish, particularly when you only have a list of profile id's for debug.
  189. |
  190. | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
  191. <profile>
  192. <id>jdk-1.4</id>
  193. <activation>
  194. <jdk>1.4</jdk>
  195. </activation>
  196. <repositories>
  197. <repository>
  198. <id>jdk14</id>
  199. <name>Repository for JDK 1.4 builds</name>
  200. <url>http://www.myhost.com/maven/jdk14</url>
  201. <layout>default</layout>
  202. <snapshotPolicy>always</snapshotPolicy>
  203. </repository>
  204. </repositories>
  205. </profile>
  206. -->
  207. <!--
  208. | Here is another profile, activated by the system property 'target-env' with a value of 'dev',
  209. | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
  210. | might hypothetically look like:
  211. |
  212. | ...
  213. | <plugin>
  214. | <groupId>org.myco.myplugins</groupId>
  215. | <artifactId>myplugin</artifactId>
  216. |
  217. | <configuration>
  218. | <tomcatLocation>${tomcatPath}</tomcatLocation>
  219. | </configuration>
  220. | </plugin>
  221. | ...
  222. |
  223. | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
  224. | anything, you could just leave off the <value/> inside the activation-property.
  225. |
  226. <profile>
  227. <id>env-dev</id>
  228. <activation>
  229. <property>
  230. <name>target-env</name>
  231. <value>dev</value>
  232. </property>
  233. </activation>
  234. <properties>
  235. <tomcatPath>/path/to/tomcat/instance</tomcatPath>
  236. </properties>
  237. </profile>
  238. -->
  239. </profiles>
  240. <!-- activeProfiles
  241. | List of profiles that are active for all builds.
  242. |
  243. <activeProfiles>
  244. <activeProfile>alwaysActiveProfile</activeProfile>
  245. <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  246. </activeProfiles>
  247. -->
  248. </settings>

1.1.6 [此步可以省略,maven自动下载]将下载的本地仓库压缩包repository.zip 中所有内容解压到本地仓库repository目录下

1.1.7  重新启动电脑,在命令符下输入 mvn -version 如果版片就说明配置成功

1.2 第二步,在 STS (或者eclipse)工具中集成 maven插件。

1.2.1 打开开发STS(或eclipse)工具,在菜单栏选择

window –preferences – maven

 

勾选 下载源码 和 javadoc文档 ,自动关联

1.2.2 配置本地 maven 环境

打开 maven - installations ,点击对窗口 add 按钮

 

配置maven插件安装路径和名称

点击finish之后,再勾选配置maven插件

1.2.3 配置 settings.xml 位置,加载到本地仓库

  点击 User Settings,将maven的核心配置文件setting.xml的磁盘路径加载到工具中

 

1.2.4 设置本地仓库的索引,才能使用仓库中下载的jar.

选择菜单栏Window –showView –other - maven - maven repository 打开 maven 仓库管理视图

 

重建本地仓库索引

 

通过以上操作就可以完成Spring Tool Suite中maven插件的安装。


Maven环境搭配总结

1.在maven的安装目录\apache-maven-3.3.9\conf下配置setting.xml文件

<localRepository>maven的本地仓库路径全路径</localRepository>

2.eclipse配置maven

1)配置mavean的安装路径:在windows - Preferences 的installcation选项中配置maven的安装全路径

2)配置maven的settting路径:在windows - Preferences的User Settings选项中配置settting的全路径名称,以及更新索引位置(reindex)

3)重新创建索引:在window --> show View中右击菜单local Reposity选择Rebuild  Index  重新创建索引



3 IDEA配置Maven

3.1 、打开IDEA配置Maven
选择File->Settings…, 搜索Maven

3.2 然后进行以下配置

然后点击Apply再点击OK可以了
3.3 导放相关Maven配置就行了

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/87463?site
推荐阅读
相关标签
  

闽ICP备14008679号