本篇只是作为自学Marven的笔记贴,基本上都是网上的各种资料的汇总,方便自己和需要的人,不用一个个去找浪费时间了。

  1. 什么是Marven

You want to start with a project, say a J2ee or Spring MVC and you are lost what is the minimum set of Jars, how should I create the folder structure, Should it be a WAR, EAR, What are the “Best Practices” for a particular kind of project ..and many others.

Maven can be described as “Project Management Tool” which helps in cleaning, building, dependency resolution, integration, running test cases among many other activities related to project lifecycle management.
All of these tasks can be carried out by good old ANT scripts as well, but it
involves manual steps to write script for all of these activities. For example,
listing all the dependencies , then downloading them and maintaining a
repository, if a version changes manage it manually — Maven provides many of
the task as “off the shelf” plugin.

  1. Marven快速入门

非常全的blog

http://tangyanbo.iteye.com/category/220107

两个简单的例子

http://www.cnblogs.com/fnng/archive/2011/12/02/2272610.html

http://www.oracle.com/technetwork/cn/community/java/apache-maven-getting-started-1-406235-zhs.html

  1. Marven文档官网

https://maven.apache.org/index.html

  1. 官方how-to

https://maven.apache.org/guides/getting-started/index.html#What_is_Maven

  1. 官方pom configuration guide

https://maven.apache.org/pom.html

  1. 核心概念

a)        
Two Key
Concepts

POM.xml: –This is heart of maven, all dependencies definition go here and
it’s instrumental in controlling the lifecycle activities of the project.

Archetype: It could be understood as “off the prototype”, for example for
generating a simple Web project what should be the project structure, what are
the required dependencies or for generating a spring MVC project what are the
required details – Some one have already defined all these, just use the
appropriate archetype and project setup will be done “automagically”. Typical
step

  • Use archetype to indicate what type of
    project to use
  • It will generate standard project
    folders
  • It will generate POM.xml

Use maven predefined command to download the dependencies. Nonetheless to
say, one need to be connected to the net for getting the jars.
There are “off the shelf” archetypes defined, I will explain below how to get
some of them in eclipse.

关于archetype的用法,在http://www.oracle.com/technetwork/cn/community/java/apache-maven-getting-started-1-406235-zhs.html的例子中有说到。

b)    
How
dependencies are resolved?

Heart of Maven is POM.xml file. All the dependencies are defined here.

<dependencies>

<dependency>

<groupId>junit</groupId>

<artifactId>junit</artifactId>

<version>3.8.1</version>

<scope>test</scope>

</dependency>

</dependencies>

First these dependencies are looked into the local repository, pointed by
M2_REPO vaiable. To see the value of this variable go to
windows->preferences->Java->BuildPath. If the needed JAR is not found
in the local repository, then Maven site is contacted to download needed JAR.

c)     
Local
repository vs Remote repository

A
repository in Maven is used to hold build artifacts and dependencies of varying
types.

There
are strictly only two types of repositories: local and remote. The local
repository refers to a copy on your own installation that is a cache of the
remote downloads, and also contains the temporary build artifacts that you have
not yet released.

Remote
repositories refer to any other type of repository, accessed by a variety of
protocols such as file:// and http://. These repositories might be a
truly remote repository set up by a third party to provide their artifacts for
downloading (for example, repo.maven.apache.org anduk.maven.org house Maven's central repository).
Other "remote" repositories may be internal repositories set up on a
file or HTTP server within your company, used to share private artifacts
between development teams and for releases.

The
local and remote repositories are structured the same way so that scripts can
easily be run on either side, or they can be synced for offline used. In
general use, the layout of the repositories is completely transparent to the
Maven user, however.

通常我们是从center repository里面去取出jar文件的。如果有必要我们可以使用就近的mirror,具体的做法在这里http://maven.apache.org/guides/mini/guide-mirror-settings.html

但是对于直接的企业应用,通常来说会搭建一个internal repository。这个操作可以通过repository manager来实现,好处有如下几点。

Proxying speeds up builds throughout your
organization by installing a local cache for all artifacts from the Central
Maven repository.

a repository manager provides an organization
with control over what is downloaded by Maven. You can include or exclude
specific artifacts from the public repository, and having this level of control
over what is downloaded from the central Maven repository is a prerequisite for
organizations which need strict control over what dependencies are used
throughout an organization.

a repository manager also provides something
essential to full adoption of Maven. Unless you expect every member of your
organization to download and build every single internal project, you will want
to provide a mechanism for developers and departments to share both SNAPSHOT
and releases for internal project artifacts. Over
time, this central deployment point for internal projects becomes the fabric
for collaboration between different development teams.

d)    
项目开发中的maven

根据我的了解,maven开发的过程基本上是这样的:

  1. 使用maven命令行mvn工具(或者eclipse插件)创建maven项目的基本框架
  2. 使用svn将整个生成的框架都check in(特别要的是pom.xml)
  3. 其他工程师从svn中check out之后,eclipse的maven插件会自动下载需要的jar包放置到local repository中。

e)    
Maven 生命周期

maven 能支持不同的生命周期,但是最常用的是默认的Maven生命周期 (default
Maven lifecycle )。如果你没有对它进行任何的插件配置或者定制的话,那么命令
mvn package 会依次执行默认生命周期中直到包括
package 阶段前的所有阶段的插件目标(其中冒号前的是插件名,后面的是target/goal(s)):

  1. process-resources 阶段:resources:resources
  2. compile 阶段:compiler:compile
  3. process-classes 阶段:(默认无目标)
  4. process-test-resources 阶段:resources:testResources
  5. test-compile 阶段:compiler:testCompile
  6. test 阶段:surefire:test
  7. prepare-package 阶段:(默认无目标)
  8. package 阶段:jar:jar

 

f)     
自建jar加入maven repository

两者都可以在官方how-to里面找到

  1. deploying jars
    to an external repository
  2. mvn install

http://www.oracle.com/technetwork/cn/community/java/apache-maven-getting-started-2-405568-zhs.html也有一个例子

   

g) maven中snapshot快照库和release发布库的区别和作用

讲到底就是一句话,

如果是snapshot版本,一定会去到remote repository的SNAPSHOT仓库中去找指定公共库的指定版本的最新SNAPSHOT。

如果是非snapshot版本(release版本),先到local repository里面去找指定公共库的指定版本,没有的话,再去remote repository里面找此库

http://www.mzone.cc/article/277.html

参考资料:

http://tangyanbo.iteye.com/category/220107

http://www.mzone.cc/article/277.html

https://maven.apache.org/pom.html

http://www.oracle.com/technetwork/cn/community/java/apache-maven-getting-started-1-406235-zhs.html

http://www.oracle.com/technetwork/cn/community/java/apache-maven-getting-started-2-405568-zhs.html

https://maven.apache.org/guides/getting-started/index.html#How_do_I_deploy_my_jar_in_my_remote_repository

https://maven.apache.org/guides/getting-started/index.html#How_do_I_make_my_first_Maven_project

https://maven.apache.org/guides/introduction/introduction-to-archetypes.html

http://chandanpandey.com/2012/11/01/maven-basic-concept-set-up-in-eclipse-and-first-project/

Marven笔记贴的更多相关文章

  1. git-简单流程(学习笔记)

    这是阅读廖雪峰的官方网站的笔记,用于自己以后回看 1.进入项目文件夹 初始化一个Git仓库,使用git init命令. 添加文件到Git仓库,分两步: 第一步,使用命令git add <file ...

  2. js学习笔记:webpack基础入门(一)

    之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...

  3. SQL Server技术内幕笔记合集

    SQL Server技术内幕笔记合集 发这一篇文章主要是方便大家找到我的笔记入口,方便大家o(∩_∩)o Microsoft SQL Server 6.5 技术内幕 笔记http://www.cnbl ...

  4. PHP-自定义模板-学习笔记

    1.  开始 这几天,看了李炎恢老师的<PHP第二季度视频>中的“章节7:创建TPL自定义模板”,做一个学习笔记,通过绘制架构图.UML类图和思维导图,来对加深理解. 2.  整体架构图 ...

  5. PHP-会员登录与注册例子解析-学习笔记

    1.开始 最近开始学习李炎恢老师的<PHP第二季度视频>中的“章节5:使用OOP注册会员”,做一个学习笔记,通过绘制基本页面流程和UML类图,来对加深理解. 2.基本页面流程 3.通过UM ...

  6. NET Core-学习笔记(三)

    这里将要和大家分享的是学习总结第三篇:首先感慨一下这周跟随netcore官网学习是遇到的一些问题: a.官网的英文版教程使用的部分nuget包和我当时安装的最新包版本不一致,所以没法按照教材上给出的列 ...

  7. springMVC学习笔记--知识点总结1

    以下是学习springmvc框架时的笔记整理: 结果跳转方式 1.设置ModelAndView,根据view的名称,和视图渲染器跳转到指定的页面. 比如jsp的视图渲染器是如下配置的: <!-- ...

  8. 读书笔记汇总 - SQL必知必会(第4版)

    本系列记录并分享学习SQL的过程,主要内容为SQL的基础概念及练习过程. 书目信息 中文名:<SQL必知必会(第4版)> 英文名:<Sams Teach Yourself SQL i ...

  9. 2014年暑假c#学习笔记目录

    2014年暑假c#学习笔记 一.C#编程基础 1. c#编程基础之枚举 2. c#编程基础之函数可变参数 3. c#编程基础之字符串基础 4. c#编程基础之字符串函数 5.c#编程基础之ref.ou ...

随机推荐

  1. atitit.常用编程语言的性能比较 c c++ java

    atitit.常用编程语言的性能比较 c c++ java 选择一个什么样的程序问题进行这样的测试呢?这是一个很关键的问题,也最容易影响测试的公平性.另外的,对于每种语言,各自的优势都是不同的 #-- ...

  2. SpringIOC&AOP

    Spring是为简化企业级系统开发而诞生的,Spring框架为J2EE应用常见的问题提供了简单.有效的解决方案,使用Spring,你可以用简单的POJO(Plain Old Java Object)来 ...

  3. 使用vs自带的性能诊断工具

    visual studio是个强大的集成开发环境,内置了程序性能诊断工具.下面通过两段代码进行介绍. static void Main( string[] args) { Test1(); Test2 ...

  4. 淘宝TOP之API测试

    下面的文章,是很早之前写的.内容过时了.主要是获取session的方法,很简单了.作为一个中小型网站开发者,淘宝API的开放大大缩短了网站的开发周期和运作效率,面对海量的数据,开发者只要仔细阅读开发文 ...

  5. android: 使用 IntentService

    9.5.2 使用 IntentService 话说回来,在本章一开始的时候我们就已经知道,服务中的代码都是默认运行在主线程 当中的,如果直接在服务里去处理一些耗时的逻辑,就很容易出现 ANR(Appl ...

  6. SCN试验之一

    在数据库运行的时候,数据库系统的SCN不断地增长: SQL> select dbms_flashback.get_system_change_number from dual; GET_SYST ...

  7. iOS:Tools:快速注释Doxygen

    Xcode5有个新特性就是自己定义的函数也会被检测集成到代码提示里面,也就是在Quick Help有提示.如 /** * @brief 设置id * * @param id 要设置的id */ +(v ...

  8. 环回接口(loopback interface)的新认识

    背景 前些日子在IDC实验docker的时候,为了避免与公司网络冲突,将bridge设置为127.x网段的IP,原以为这样就OK,后来发现在访问container内部的服务的时候无法访问.开始以为ip ...

  9. Android UI系列-----Dialog对话框

    您可以通过点击 右下角 的按钮 来对文章内容作出评价, 也可以通过左下方的 关注按钮 来关注我的博客的最新动态. 如果文章内容对您有帮助, 不要忘记点击右下角的 推荐按钮 来支持一下哦 如果您对文章内 ...

  10. 分享自己写的一个小工具RGB转十六进制(高手勿喷)

    由于工作经常美工给的颜色是rgb,而我们网页里面是16进制.网上也有很多类型的工具.不过似乎都用浏览器打开.没网就不爽了 实现也很简单.代码已经共享了 http://git.oschina.net/w ...