首页 > 其他 > 详细

从maven安装配置到idea成功创建maven项目

时间:2019-11-23 00:53:33      阅读:130      评论:0      收藏:0      [点我收藏+]

在文章开始之前,我还是想安抚下你躁动的心情,说实话这一套操作下来的确花了我不少时间,的确头疼.

不过对于现在在看文章的你,我还是想提倡多多尝试,耐心哈,别砸键盘......废话少说切入正题

一. maven安装

  1.确保本地装有JDK

  2.去官网:http://maven.apache.org/download.cgi 下载自己所需的版本(在这说明,windows的安装包zip结尾)

  3.解压本地,配置环境变量(其他博客有很多提及,在这我就不多截屏和引用了,篇幅过多)

二. 检测maven是否安装成功

  1.WINDOWS+R  进cmd  在dos窗口 敲入  mvn -v

  2.若出现下图,说明maven安装成功并且环境变量配置成功

  技术分享图片

 

 

三. maven配置文件setting的配置

 

  md....在这困了两天都没配好,百度了好久,什么改本地仓库,改镜像环境,改什么什么.....巴拉巴拉.....

 

  楼主把百度的maven教程和博客的都翻遍了,还是出错,说到底咱们百度那么多不就为了能正常使用maven吗?直接提供个settings文件如下,简单粗暴

 

  

  1 <?xml version="1.0" encoding="UTF-8"?>
  2 
  3 <!--
  4 Licensed to the Apache Software Foundation (ASF) under one
  5 or more contributor license agreements.  See the NOTICE file
  6 distributed with this work for additional information
  7 regarding copyright ownership.  The ASF licenses this file
  8 to you under the Apache License, Version 2.0 (the
  9 "License"); you may not use this file except in compliance
 10 with the License.  You may obtain a copy of the License at
 11 
 12     http://www.apache.org/licenses/LICENSE-2.0
 13 
 14 Unless required by applicable law or agreed to in writing,
 15 software distributed under the License is distributed on an
 16 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17 KIND, either express or implied.  See the License for the
 18 specific language governing permissions and limitations
 19 under the License.
 20 -->
 21 
 22 <!--
 23  | This is the configuration file for Maven. It can be specified at two levels:
 24  |
 25  |  1. User Level. This settings.xml file provides configuration for a single user, 
 26  |                 and is normally provided in ${user.home}/.m2/settings.xml.
 27  |
 28  |                 NOTE: This location can be overridden with the CLI option:
 29  |
 30  |                 -s /path/to/user/settings.xml
 31  |
 32  |  2. Global Level. This settings.xml file provides configuration for all Maven
 33  |                 users on a machine (assuming they‘re all using the same Maven
 34  |                 installation). It‘s normally provided in 
 35  |                 ${maven.home}/conf/settings.xml.
 36  |
 37  |                 NOTE: This location can be overridden with the CLI option:
 38  |
 39  |                 -gs /path/to/global/settings.xml
 40  |
 41  | The sections in this sample file are intended to give you a running start at
 42  | getting the most out of your Maven installation. Where appropriate, the default
 43  | values (values used when the setting is not specified) are provided.
 44  |
 45  |-->
 46 <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" 
 47           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 48           xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
 49   <!-- localRepository
 50    | The path to the local repository maven will use to store artifacts.
 51    |
 52    | Default: ${user.home}/.m2/repository
 53   <localRepository>/path/to/local/repo</localRepository>
 54   -->
 55 
 56    <!-- 写你本地的仓库路径 -->
 57 
 58   <localRepository>D:\maven_repository</localRepository>
 59 
 60   
 61   <!-- interactiveMode
 62    | This will determine whether maven prompts you when it needs input. If set to false,
 63    | maven will use a sensible default value, perhaps based on some other setting, for
 64    | the parameter in question.
 65    |
 66    | Default: true
 67   <interactiveMode>true</interactiveMode>
 68   -->
 69 
 70 
 71   <!-- offline
 72    | Determines whether maven should attempt to connect to the network when executing a build.
 73    | This will have an effect on artifact downloads, artifact deployment, and others.
 74    |
 75    | Default: false
 76   <offline>false</offline>
 77   -->
 78 
 79 
 80   <!-- pluginGroups
 81    | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
 82    | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
 83    | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
 84    |-->
 85   <pluginGroups>
 86     <!-- pluginGroup
 87      | Specifies a further group identifier to use for plugin lookup.
 88     <pluginGroup>com.your.plugins</pluginGroup>
 89     -->
 90     <pluginGroup>org.mortbay.jetty</pluginGroup>
 91   </pluginGroups>
 92 
 93 
 94   <!-- proxies
 95    | This is a list of proxies which can be used on this machine to connect to the network.
 96    | Unless otherwise specified (by system property or command-line switch), the first proxy
 97    | specification in this list marked as active will be used.
 98    |-->
 99   <proxies>
100     <!-- proxy
101      | Specification for one proxy, to be used in connecting to the network.
102      |
103     <proxy>
104       <id>optional</id>
105       <active>true</active>
106       <protocol>http</protocol>
107       <username>proxyuser</username>
108       <password>proxypass</password>
109       <host>proxy.host.net</host>
110       <port>80</port>
111       <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
112     </proxy>
113     -->
114   </proxies>
115 
116 
117   <!-- servers
118    | This is a list of authentication profiles, keyed by the server-id used within the system.
119    | Authentication profiles can be used whenever maven must make a connection to a remote server.
120    |-->
121   <servers>
122 
123     <server>
124         <id>releases</id>
125         <username>ali</username>
126         <password>ali</password>
127       </server>
128       <server>
129         <id>Snapshots</id>
130         <username>ali</username>
131         <password>ali</password>
132       </server>
133   </servers>
134 
135 
136  
137   <mirrors>
138     <!-- mirror
139      
140      
141 
142     <mirror>
143       <id>mirrorId</id>
144       <mirrorOf>repositoryId</mirrorOf>
145       <name>Human Readable Name for this Mirror.</name>
146       <url>http://my.repository.com/repo/path</url>
147     </mirror>
148      -->
149     <mirror>
150       <!--This sends everything else to /public -->
151       <id>nexus</id>
152       <mirrorOf>*</mirrorOf> 
153       <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
154     </mirror>
155     <mirror>
156       <!--This is used to direct the public snapshots repo in the 
157           profile below over to a different nexus group -->
158       <id>nexus-public-snapshots</id>
159       <mirrorOf>public-snapshots</mirrorOf> 
160       <url>http://maven.aliyun.com/nexus/content/repositories/snapshots/</url>
161     </mirror>
162   </mirrors>
163   
164   
165   <profiles> 
166     <profile>
167       <id>development</id>
168       <repositories>
169         <repository>
170           <id>central</id>
171           <url>http://central</url>
172           <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
173           <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
174         </repository>
175       </repositories>
176      <pluginRepositories>
177         <pluginRepository>
178           <id>central</id>
179           <url>http://central</url>
180           <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
181           <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
182         </pluginRepository>
183       </pluginRepositories>
184     </profile>
185     <profile>
186       <!--this profile will allow snapshots to be searched when activated-->
187       <id>public-snapshots</id>
188       <repositories>
189         <repository>
190           <id>public-snapshots</id>
191           <url>http://public-snapshots</url>
192           <releases><enabled>false</enabled></releases>
193           <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
194         </repository>
195       </repositories>
196      <pluginRepositories>
197         <pluginRepository>
198           <id>public-snapshots</id>
199           <url>http://public-snapshots</url>
200           <releases><enabled>false</enabled></releases>
201           <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
202         </pluginRepository>
203       </pluginRepositories>
204     </profile>
205   </profiles>
206  
207    <activeProfiles>
208     <activeProfile>development</activeProfile>
209     <activeProfile>public-snapshots</activeProfile>
210    </activeProfiles>
211 </settings>

 

 

 

 

  上面的setting文件,使用的是国内的阿里云镜像环境,使用时只需将本地仓库的路径改下即可,整个文件直接放入maven文件夹下conf文件夹中,

  为保险起见,博主建议在本地仓库文件夹中也放一份

  ok,操作完这些,总得检测下是否配置正确

四. 检测本地maven的配置情况是否成功

  1.windows+R 进cmd  敲入 mvn help:system

  2.若出现下图,说明配置成功

  技术分享图片

 

 

   至此,maven的安装配置结束

五.在idea中创建maven项目

  先说明下,如果你之前在idea创建maven项目失败,楼主建议将idea的配置全部删除,重新格式化idea配置,不然以下方法依然解决不了问题(亲测)

  1.打开idea  File > New > Project     选中Maven    

  2.在 Create from archetype 前面打对勾

  3.选择 如图所示 然后 next

  技术分享图片

 

  

  4.随便填

   技术分享图片

 

 

  5.这里一定要填写正确,填写maven的安装路径和配置文件 以及自己的仓库路径

  技术分享图片

 

 

 6. 填写项目名,设置项目路径  然后finish

  技术分享图片

 

 

7. 如下图,若出现maven在控制台加载 可以选择让maven自动加载 Enable Auto Import

          技术分享图片

 

 

  第一次加载可能会有点慢,因为本地没有jar包,需要去下载

  ok 至此maven项目搭建完成    点开项目的pom文件,即可添加项目所需jar包的连接,maven即可正常使用

  下图为项目文件列表

  技术分享图片

 

 

  好了,开始 coding 吧 ,楼主记住了这次教训,花费大把时间,属实蛋疼 

  参考博客 : https://www.cnblogs.com/deep-space/p/9542566.html

 

 

 

  

 

  

 

 

 

 

从maven安装配置到idea成功创建maven项目

原文:https://www.cnblogs.com/bcmb/p/11914981.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!