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 ...
随机推荐
- ios开发数据库版本迁移手动更新迭代和自动更新迭代艺术(二)
由于大家都热衷于对ios开发数据库版本迁移手动更新迭代和自动更新迭代艺术(一)的浏览下面我分享下我的源文件git仓库: 用法(这边我是对缓存的一些操作不需要可以省去):https://github.c ...
- IPFS: Merkle DAG数据结构
今天带大家来深入探索一下IPFS的核心数据结构Merkle DAG 什么是 Merkle DAG? Merkle DAG是IPFS系统的核心概念之一,当然Merkle DAG并不是IPFS团队发明的, ...
- 笔记:Struts2 拦截器
配置拦截器 Struts.xml 配置文件中,使用<interceptor-/>来定义拦截器,有属性 name 表示拦截器的名称,class 表示拦截器的具体首先类,可以使用<par ...
- 【Python】 文件目录比较工具filecmp和difflib
在一些运维场景中,常常需要比较两个环境中的应用目录结构(是否有文件/目录层面上的增删)以及比较两个环境中同名文件内容的不同(即文件层面上的改).Python自带了两个内建模块可以很好地完成这个工作,f ...
- 【Linux】 升级CentOS6的内核到3.10
升级内核 最近有一些虚拟机,想装Dokcer,但是实验之后发现Docker基本上只在3.0以上的linux内核版本中才能稳定运行.所以就面临着把CentOS6的2.6内核升级到3.0以上.下面提供两种 ...
- 【Python】 迭代器&生成器
迭代器 任何一个类,只要其实现了__iter__方法,就算是一个可迭代对象.可迭代对象的__iter__方法返回的对象是迭代器,迭代器类需要实现next方法.一般来说,实现了__iter__方法的类肯 ...
- Git详细教程(2)---多人协作开发
Git可以完成两件事情: 1. 版本控制 2.多人协作开发 如今的项目,规模越来越大,功能越来越多,需要有一个团队进行开发. 如果有多个开发人员共同开发一个项目,如何进行协作的呢. Git提供了一个非 ...
- SpringMVC学习笔记三 整合jdbc和事务
spring整合JDBC spring提供了很多模板整合Dao技术,用于简化编程. 引入相关jar包 spring中提供了一个可以操作数据库的对象,JDBCTemplate(JDBC模板对象).对象封 ...
- java程序在没有java环境的电脑上执行的方法(关键词jar,exe)
可以让你写的java程序在别人没有任何java配置以及环境的情况下执行 写好程序 在程序对应的package上右键->export->java->Runnable JAR file- ...
- 刚入大学B. http://mp.weixin.qq.com/s/ORpKfX8HOQEJOYfwvIhRew
自己对计算机还是比较感兴趣的,经过不断的努力,我相信我可以在这一专业中显露头角,我会努力向博主学习.理想的大学是自由,快乐,可以学到很多知识的地方,未来我想在lt行业进行软件开发等项目,为了梦想我会不 ...