maven的使用之一简单的安装
首先,我们知道,在传统的项目中,我们会导入一堆的jar包,那样的话,我们会发现我们的jar包的大小已经占了整个项目大小的90%以上,甚至更多,而且,我们的jar包只能自己使用,如果 其他人想用的话,还得再搞一份jar包,而且我们的这些jar包版本也不能统一,再说去搞那些jar包的话更繁琐
但现在就不一样了,我们有了maven的出现,从此,我们的jar包什么的,就不用我们去管理了,那么我们的maven是怎么对jar包进行管理的?我们为什么能在我们的项目中使用那些jar包呢?
其实,我们的maven项目中你是找不到jar包的,它的jar包在我们的仓库中,这样的话,在我们的项目中,我们可以在pom.xml中配置我们的所使用的jar包坐标,我们要确定一个jar包的话,我们需要先知道它的公司信息,即域名倒序,然后项目信息,即项目名称,最后就是版本信息,我们以struts2-core.2.3.24.jar来说,我们需要先知道这个是哪个公司的?这里,我们的struts2是Apache组织下的,再说项目信息,就是struts2-core项目,后面的2.3.24就是具体的版本信息,这样我们就可以根据我们jar包信息去我们的仓库中去找我们对应的jar包,这里,我们先引出maven中仓库的概念,下次我们再对这个仓库进行细说
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.24</version>
</dependency>
这里,我们就明白了,我们的maven项目是通过pom.xml文件中配置的jar的坐标去我们的仓库中找对应的jar包
说了半天,还没有安装我们的maven,其实maven的安装很简单,我们在官网上下载maven,地址http://maven.apache.org/download.cgi,完了我们直接解压就行,我们的maven项目想要运行起来,还要配置我们的系统变量,我们打开我们电脑的控制面板里面的环境变量配置
我先说一下配置的系统变量的步骤:
第一步:就是打开我们的控制面板->系统->高级系统设置
第二步:进入高级系统设置->环境变量
第三步:新建->变量名:MAVEN_HOME 变量值:我们安装的maven的路径(往下能看到bin目录),完了点击确定即可
第四步:点击Path,然后点击编辑,在编辑环境变量中点击新建,完了把我们的%MAVEN_HOME%\bin加入进去,点击确定可以了
我们先来测试一下我们的maven是不是可以用了?使用mvn -v

这里我们要注意几个问题:
1.我们在配置MAVEN_HOME时,一定要看到我们的maven解压缩后的bin目录
2.MAVEN_HOME的配置,必须用到JAVA_HOME
3.JAVA_HOME的配置,必须看到bin目录
4.JAVE_HOME的路径,不要有空格和特殊字符
5.如果我们在输入mvn -v时,没有看到jre,那就是JDK安装出现问题
我们可以在自己的maven配置文件中加入我们本地仓库的位置
第一步:我们需要打开我们的maven\conf\settings.xml文件
第二步:需要在这个文件中加入本地仓库的配置(就一句话)
<?xml version="1.0" encoding="UTF-8"?> <!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
--> <!--
| This is the configuration file for Maven. It can be specified at two levels:
|
| 1. User Level. This settings.xml file provides configuration for a single user,
| and is normally provided in ${user.home}/.m2/settings.xml.
|
| NOTE: This location can be overridden with the CLI option:
|
| -s /path/to/user/settings.xml
|
| 2. Global Level. This settings.xml file provides configuration for all Maven
| users on a machine (assuming they're all using the same Maven
| installation). It's normally provided in
| ${maven.home}/conf/settings.xml.
|
| NOTE: This location can be overridden with the CLI option:
|
| -gs /path/to/global/settings.xml
|
| The sections in this sample file are intended to give you a running start at
| getting the most out of your Maven installation. Where appropriate, the default
| values (values used when the setting is not specified) are provided.
|
|-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- 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>F:\java\develop\maven\mavenRepository\repository</localRepository> <!-- interactiveMode
| This will determine whether maven prompts you when it needs input. If set to false,
| maven will use a sensible default value, perhaps based on some other setting, for
| the parameter in question.
|
| Default: true
<interactiveMode>true</interactiveMode>
--> <!-- offline
| Determines whether maven should attempt to connect to the network when executing a build.
| This will have an effect on artifact downloads, artifact deployment, and others.
|
| Default: false
<offline>false</offline>
--> <!-- pluginGroups
| This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
| when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
| "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
|-->
<pluginGroups>
<!-- pluginGroup
| Specifies a further group identifier to use for plugin lookup.
<pluginGroup>com.your.plugins</pluginGroup>
-->
</pluginGroups> <!-- proxies
| This is a list of proxies which can be used on this machine to connect to the network.
| Unless otherwise specified (by system property or command-line switch), the first proxy
| specification in this list marked as active will be used.
|-->
<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
| This is a list of authentication profiles, keyed by the server-id used within the system.
| Authentication profiles can be used whenever maven must make a connection to a remote server.
|-->
<servers>
<!-- server
| Specifies the authentication information to use when connecting to a particular server, identified by
| a unique name within the system (referred to by the 'id' attribute below).
|
| NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
| used together.
|
<server>
<id>deploymentRepo</id>
<username>repouser</username>
<password>repopwd</password>
</server>
--> <!-- Another sample, using keys to authenticate.
<server>
<id>siteServer</id>
<privateKey>/path/to/private/key</privateKey>
<passphrase>optional; leave empty if not used.</passphrase>
</server>
-->
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers> <!-- 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
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
</mirrors> <!-- 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.
|
| NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
| repositories, plugin repositories, and free-form properties to be used as configuration
| variables for plugins in the 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.
<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:
|
| ...
| <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.
|
<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>
<!--profile的id-->
<id>dev</id>
<repositories>
<repository>
<!--仓库id,repositories可以配置多个仓库,保证id不重复-->
<id>nexus</id>
<!--仓库地址,即nexus仓库组的地址-->
<url>http://localhost:8081/nexus/content/groups/public/</url>
<!--是否下载releases构件-->
<releases>
<enabled>true</enabled>
</releases>
<!--是否下载snapshots构件-->
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<!-- 插件仓库,maven的运行依赖插件,也需要从私服下载插件 -->
<pluginRepository>
<!-- 插件仓库的id不允许重复,如果重复后边配置会覆盖前边 -->
<id>public</id>
<name>Public Repositories</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles> <activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
<!-- activeProfiles
| List of profiles that are active for all builds.
|
<activeProfiles>
<activeProfile>alwaysActiveProfile</activeProfile>
<activeProfile>anotherAlwaysActiveProfile</activeProfile>
</activeProfiles>
-->
</settings>
因为我们使用的是eclipse工具进行开发,我们需要在我们的eclipse中进行maven的配置
第一步:点击window->preferences->Maven->Installations->Add->寻找我们的maven解压后的目录(下面能看到bin目录为止),点击finish即可
第二步:把自己添加的maven这个给勾选上
第三步:点击Maven->User Settings->看一下这里面有没有问题,一个是settings.xml文件的位置,一个是本地仓库的位置,这个仓库地址不需要自己写(自动补充),完了点击确定就可以了
第四步:点击window->show View->Maven Repositories,点击确定就行
第五步:在我们eclipse底部会有我们的仓库,我们右键Local Repositories,点击Rebuild Index即可,这时,我们就可以看到我们本地仓库中的jar包了
先到这里吧,下次说下我们的maven的仓库
maven的使用之一简单的安装的更多相关文章
- CocoaPods 的简单快速安装方法
CocoaPods 的简单快速安装方法(Setting up CocoaPods master repo 卡着不动,是因为淘宝镜像已经不能用了. 一.git clone方法安装cocoapods 镜像 ...
- Maven 系列 一 :Maven 快速入门及简单使用【转】
开发环境 MyEclipse 2014 JDK 1.8 Maven 3.2.1 1.什么是Maven? Maven是一个项目管理工具,主要用于项目构建,依赖管理,项目信息管理. 2.下载及安装 下载最 ...
- Maven(3.0.5) 环境的安装配置
Maven 安装步骤 JDK 安装:在使用 Maven 之前,要确定已经安装了 JDK. huey@huey-K42JE:~$ java -version java version "1.7 ...
- 使用maven+eclipse搭建最简单的struts2的helloworld
使用maven+eclipse搭建最简单的struts2的helloworld 一.web分层结构简介 1.web[细]粒度分层结构: 按细粒度分层可以分为以下6种: 1).表现层:html/css/ ...
- 超简单Mac安装Tomcat服务器
超简单Mac安装Tomcat服务器 1.首先下载tomcat 下载连接 2. 解压并改名 3.把Tomcat复制到系统中的资源库或者Library 4.打开shell,进入Tomcat下面的bin目录 ...
- 超简单Windows安装Scrapy (仅需一步)
网上很多关于windows安装Scrapy的教程都非常的繁琐,请看我给大家分享的教程,非常简单 一步完成. 超简单的安装方法: 下载地址: https://www.continuum.io/downl ...
- Maven 系列 一 :Maven 快速入门及简单使用
开发环境 MyEclipse 2014 JDK 1.8 Maven 3.2.1 1.什么是Maven? Maven是一个项目管理工具,主要用于项目构建,依赖管理,项目信息管理. 2.下载及安装 下载最 ...
- Jenkins的安装(最为简单的安装方法)
1.Jenkins的安装(最为简单的安装方法) (1)下载Jenkins(一个war文件) (2)cmd运行:java -jar jenkins.war [Jenkins需要IDK1.5以上的版本] ...
- nno Setup入门(一)——最简单的安装脚本
一个最简单的安装脚本: 1.最简单的安装文件脚本: [setup] AppName=Test AppVerName=TEST DefaultDirName="E:\TEST" Ap ...
随机推荐
- Java equals() 和hashCode()方法详解
Java的Object类中定义了equals方法,Object类中的equals方法源代码如下,从源代码中可以看出Object类中的equals方法是用来返回判断两个对象是否指向同一个对象(引用地址) ...
- 【Unity与23种设计模式】装饰模式(Decorator)
GoF中定义: "动态地附加额外的责任给一个对象.装饰模式提供了一个灵活的选择,让子类可以用来扩展功能." 装饰模式一般用来增加新功能 它可以避免更改已经实现的程序代码 从而增加系 ...
- 关于Sql server数据 MD5加密
最近在写一个web项目时,需要在数据库中将用户密码等一类信息进行加密处理.数据加密算法有许多 ,各有各的优缺点;在 http://www.cnblogs.com/yangywyangyw/arch ...
- http协议中302和303的区别
http1.0协议中只有302码,没有303状态码:http1.1,在默认情况下,很多服务端基础程序,为了兼容http1.0,在遇到本应响应303时,也给客户端响应了302. 碰到的问题: 场景: 在 ...
- linux(ubuntu)环境下安装IDEA
想调试java虚拟机内存溢出的情况,在调试过程中总会出现一些不可预见的状况,正好在学linux,在windows上安装了虚拟机,安装的镜像是ubuntu(乌班图)装在了虚拟机中,装在虚拟机中好处是即使 ...
- 解决 python 中,时间日期不能序列化的问题
在python 中, 你在数据库娶到了数据中如果含有时间日期,那么你在向前端作为json对象传递的时候呢,就会报错.大致如下: TypeError: datetime.datetime(2017, 1 ...
- 【原创】开启PowerShell远程管理
非域网络,开启PowerShell远程管理,命令如下: 以下操作,PS命令窗口,必须都以管理员省份执行. Step 1: 机器A和B,分别开启PowerShell远程管理服务A = 192.168.3 ...
- POJ-1032-拆数字
Description New convocation of The Fool Land's Parliament consists of N delegates. According to the ...
- 如何使用一次for循环得到数组中第二大的数和第三大的数
装载声明:http://blog.csdn.net/lxsmk9059/article/details/77920206?locationNum=1&fps=1 ,,,,,,,,}; ]; ] ...
- (工具类)double类型数据运算
package com.flf.util;import java.math.BigDecimal;/** * double类型数据运算 * @author Yancy 2016-12-14 * */p ...