`
nanjingjiangbiao_T
  • 浏览: 2595431 次
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

maven and ant

 
阅读更多

Ant 将提供了很多可以重用的task,例如 copy, move, delete 以及junit 单元测试Maven 则提供了很多可以重用的过程。 我们可以把 Maven 看成是一个 "build container"这个容器可以让我们重用从一系列的项目中抽像出来的build过程。

使用过Ant的朋友都会有这样的体会吧。 Ant提供的task级别描述,我们可以通过想写shell一样一个Java项目的build过程来进行描述。我们可以写好一个build.xml 文件,来解决我们在Java程序运行编译过程中需要解决的classpath,以及相关参数的配置问题,只有是项目中的主要结构以及依赖的库不变,我们很少去修改build.xml。但是如果我们要开发一个新的项目即使原有项目的build.xml写的即使再好,其能够复用得模块还是比较少的。特别是对项目的结构进行修改后,想不修改build.xml都很困难。这是因为Ant 所提供的可重用的task粒度太小,虽然灵活性很强,但是我们需要纠缠很多细节的东西。

正如你所在使用Servlet 容器时,并没有告诉它如何去解包WAR文件,在你使用Maven 时,你也不需要告诉Maven 如何build你的项目。 Maven提供了一套抽象层用来分离项目的build 逻辑。许多人一开始就被Maven所提供的依赖管理(可以通过XML来描述项目所依赖的库的关系)打动,但是使用Maven的主要好处还是它能为提供一个标准的开发构架用来对多个项目进行管理。 依赖管理只是这个标准开发构架所提供的一个副产品。

如果想让Maven实现某个build过程,例如compile, test, install,我们可以通过写plugin的方式,很容易就实现build过程的复用。Maven可以为我们提供一个很舒适的build环境,我们不需要通过build.xml定义繁琐的build过程, 只需要告诉这些build过程的plugin,我现在的文件依赖的那些第三方库,我需要实现什么样的build功能,就足够了。那些繁琐的路径配置信息,以及复杂的第三方库下载设置,你通通不用考虑, Maven 以及它的plugin都帮你实现了。

第一:ant脚本是可以直接运行在maven中的。maven和ant最大的差别就是在于maven的编译以及所有的脚本都有一个基础,就是POM(project object model)。这个模型定义了项目的方方面面,然后各式各样的脚本在这个模型上工作,而ant完全是自己定义,显然maven更胜一筹。


第二:Maven对所依赖的包有明确的定义,如使用那个包,版本是多少,一目了然。而ant则通常是简单的inclde 所有的jar。导致的最终结果就是,你根本无法确定JBoss中的lib下的common-logging 是哪个版本的,唯一的方法就是打开 META-INF 目录下MANIFEST.MF。估计JBoss迟早会转向Maven的。


第三:Maven是基于中央仓库的编译,即把编译所需要的资源放在一个中央仓库里,如jar,tld,pom,等。当编译的时候,maven会自动在仓库中找到相应的包,如果本地仓库没有,则从设定好的远程仓库中下载到本地。这一切都是自动的,而ant需要自己定义了。这个好处导致的结果就是,用maven编译的项目在发布的时候只需要发布源码,小得很,而反之,ant的发布则要把所有的包一起发布,显然maven又胜了一筹。


第四:maven有大量的重用脚本可以利用,如生成网站,生成javadoc,sourcecode reference,等。而ant都需要自己去写。试试 maven site 的效果。


第五:maven目前不足的地方就是没有象ant那样成熟的GUI界面,不过mavengui正在努力中。目前使用maven最好的方法还是命令行,又快又方便。

分享到:
评论

相关推荐

    maven-ant-tasks-2.1.3-src

    The Mavent Ant Tasks allow several of Maven's artifact handling features to be used from within an Ant build. These include: Dependency management - including transitive dependencies, scope ...

    Wrox.Press.Professional.Java.Tools.for.Extreme.Programming.eBook-LiB.part3

    In the last few years, open source developers have created or significantly improved a host of Java XP tools, from XDoclet, Maven, AntHill, and Eclipse to Ant, JUnit, and Cactus. This practical, code...

    Wrox.Press.Professional.Java.Tools.for.Extreme.Programming.eBook-LiB.part4

    In the last few years, open source developers have created or significantly improved a host of Java XP tools, from XDoclet, Maven, AntHill, and Eclipse to Ant, JUnit, and Cactus. This practical, code...

    Professional Java Tools for Extreme Programming (JAVA经典书籍英文版)_part2

    In the last few years, open source developers have created or significantly improved a host of Java XP tools, from XDoclet, Maven, AntHill, and Eclipse to Ant, JUnit, and Cactus. This practical, code...

    Professional Java Tools for Extreme Programming (JAVA经典书籍英文版)_part1

    In the last few years, open source developers have created or significantly improved a host of Java XP tools, from XDoclet, Maven, AntHill, and Eclipse to Ant, JUnit, and Cactus. This practical, code...

    maven-ant-tasks-2.1.3

    The Mavent Ant Tasks allow several of Maven's artifact handling features to be used from within an Ant build. These include: Dependency management - including transitive dependencies, scope ...

    maven-and-osgi

    In terms of capabilities, Maven is an improvement to Apache Ant-thanks to numerous plug-ins and built-in integration with unit testing frameworks such as JUnit. Tired of writing the same build logic ...

    maven compare to the ant

    this document is reference to the compile and build

    Maven权威指南 很精典的学习教程,比ANT更好用

    Maven是Ant的另一种选择么? 1.7. 比较Maven和Ant 1.8. 总结 2. 安装和运行Maven 2.1. 验证你的Java安装 2.2. 下载Maven 2.3. 安装Maven 2.3.1. 在Mac OSX上安装Maven 2.3.2. 在Microsoft Windows上安装...

    apache-maven-3.1.0-src and bin

    由于 Maven 的缺省构建规则有较高的可重用性,所以常常用两三行 Maven 构建脚本就可以构建简单的项目,而使用 Ant 则需要十几行。事实上,由于 Maven 的面向项目的方法,许多 Apache Jakarta 项目现在使用 Maven,...

    maven definitive guide

    A build tool such as Ant is solely focused on preprocessing, compilation, packaging, testing, and distribution. A project management tool such as Maven provides a superset of features found in a ...

    maven入门到精通

    在 Java世界中我们很多的开发人员选择用 Ant来构建项目,一个 build.xml能够完成编译、测试、打包、部署等很多任务,但我们也碰到了很多的问题,如 jar文件管理混乱,各个项目结构和 build.xml相差很大等等。...

    Maven2 的新特性.7z

    现在想来,当时从 Ant 移情 Maven 的想法其实很朴素,就是因为 Maven 可以以网站的形式展现与项目相关的信息,如开发人员列表、各种 Report。这种方式为项目的构建带来了极大的方便,尤其是 Report 的。试想对于产生...

    Maven权威指南中文版(完整)

    1.7. 比较Maven和Ant ................................................ 5 1.8. 总结 .......................................................... 9 2. 安装和运行Maven ..........................................

    maven学习资料,通过这基本书可以很快上手,包含chm文档

    In terms of capabilities, Maven is an improvement to Apache Ant-thanks to numerous plug-ins and built-in integration with unit testing frameworks such as JUnit. Tired of writing the same build logic ...

    Jenkins+Configurations+and+Build+and+Publish.doc

    Jenkins是一个开源的、提供友好操作界面的持续集成(CI)工具,起源于Hudson...常用的版本控制工具有SVN、GIT,构建工具有Maven、Ant、Gradle。 是一个 Coucourse 的同类型替代软件, 有 Mac,Windows,Linux 版本。

    Building and Testing with Gradle

    Discover how Gradle improves on the best ideas of Ant, Maven, and other build tools, with standards for developers who want them and lots of flexibility for those who prefer less structure.

    junit in action 第2版 源码 part2

    2 Set the ANT_HOME environment variable to [ant_home] and add ANT_HOME\bin (or ANT_HOME/bin) to the PATH environment variable Installing Maven ---------------- 1 Download Maven from ...

    junit in action 第2版 源码 part6

    2 Set the ANT_HOME environment variable to [ant_home] and add ANT_HOME\bin (or ANT_HOME/bin) to the PATH environment variable Installing Maven ---------------- 1 Download Maven from ...

Global site tag (gtag.js) - Google Analytics