分享
 
 
 

译:Apache Maven-简化java的构建过程--比apache ant更多(1) 未完成

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

原文: Apache Maven Simplifies the Java Build Process—Even More Than Ant

http://www.devx.com/java/Article/17204

apache maven,一个潜在的基于java的apache ant的构建工具的替代者.承诺消除维护复杂的构建脚本的争论.

这个新工具可以自动化java的构建过程.给maven一点项目的关于目录结构的信息让它来处理剩余的.所有需要的构建项目的功能已经构建到Maven中去了.换一句话说,对于一个标准的构建过程,你不必创建自定义的构建脚本.

在本文中,我将解释什么是maven和它将要解决什么问题.然后我将带你用maven自动化你自己的构建过程.作为在java中最流行的构建工具ant,此文件假设读者有对ant的基本了解.

构建过程使每天的任务自动化

作为一个程序员,花大把的时间在使其他的任务自动化,IDE自动化了我们大部分工作,但是许多开发者还是不得不使用外部工具来完成特别的任务:构建过程.构建的概念发展了多年,但是现在的构建工具只是提供了一些开发者在开发过程中开发,编译,测试和部署任务的自动化.

对于我的工作,我勉强使用多用途的

ant允许你自定义任务,它可以跨项目重用.这也许使ant成功的原因吧,但是即使有可重用的任务,你仍然要

For my work, I am grudgingly using a general-purpose, scripting language more and more with the build tool—not unlike the macro languages built into IDEs. Table 1 shows a few of the build functions that I perform daily.

Table 1. Daily Build Functions I Perform

Compile Run jikes or javac

Copy Copy resource files into the classes directory

Clean Delete the classes directory so that our next compile will be a clean compile

Delete any temporary, app-server-generated files

Recreate the classes directory

Jar Zip up a project in to a .jar file

Javadoc Generate documentation from source code

Test Use JUnit to run the project's unit tests

Deploy Copy runtime files to a staging server

Kodo Run Kodo's JDO byte-code enhancer (Kodo is a JDO implementation that post-processes class files to make them persistence-capable.)

Move Over Ant, Maven Is Here

When I first started using Ant to automate the above-mentioned tasks, it was a big timesaver. Especially once I learned to use and create custom Ant Tasks. But that was for individual, fairly simple projects. I now use Ant to automate build tasks for multiple, complex projects. A considerable part of my day is spent creating and maintaining complex Ant scripts. Over time, maintaining these scripts became a major thorn in my side.

Specifically, the following Ant limitations led me to start looking for a new build tool:

Cross-project reuse. My 10 Ant build scripts are mostly the same. So I started looking for code reuse features in Ant. As it turns out, Ant has no convenient way to reuse targets across projects. Copy-and-paste is the only choice.

Cross-developer reuse. Most of my Ant scripts are complex but not particularly unique to my project. In other words, since most of my build scripts perform the same functions as other people's build scripts, why should I have to create a build script at all—other than for project-specific functionality?

Logic and looping. As mentioned previously, I now use Ant for general-purpose scripting. Therefore, I need general-purpose scripting features, like conditional logic, looping constructs, and reuse mechanisms. Ant was never meant to be a general-purpose scripting tool, however. As such, although possible via the Script Task or a custom Task, adding conditional logic and looping to the Ant build process is awkward.

To be fair, Ant does allow you to create custom Tasks, which are reusable across projects. These are a great help and probably are the reason for Ant's success. However, even with reusable Tasks, you still end up with numerous, mostly redundant Targets in each project. If your objective is to simplify or eliminate the build script, you need something more. You need reusable Target Libraries. That's where Maven comes in.

Maven addresses these issues. With this new tool, targets (which Maven calls goals) are reusable (See the sidebar "Maven Term and Concept Summary" for a complete listing of Maven terminology.). In fact, for the most common tasks, Maven has already created the goals. This means you don't have to create them yourself. For simple projects, you may not need a build file at all. (See the sidebar "Maven Versus Ant" for a comparative analysis of Ant and Maven.)

Maven + POM = Goals Achieved

To achieve its magic, Maven uses a Project Object Model (POM), which describes a project in the form of an XML file, project.xml. Specifically, it describes the project's directory structure, its jar file dependencies, and some of its project management details. Think of the POM as project meta-data. Once you describe your project to Maven by creating the POM, you can invoke any of Maven's built-in goals (remember, a goal is like an Ant target).

The following sections demonstrate Maven. They walk you step by step through creating a simple project and invoking some of the Maven-provided goals.

安装Maven

1.下载,安装 http://maven.apache.org/start/download.html

2.设置环境变量MAVEN_HOME,如果是下载的exe安装文件,在windows平台上安装程序会自动设置.如果你下载的zip包或其他压缩包,那么你必须手动设置这个环境变量.

3.添加%MAVEN_HOME%\bin到PATH中去.

4.为了避免重复下载资源库,运行install_repo.bat C:\Documents and Settings\Administrator\.maven\repository把%MAVEN_HOME%\lib中的插件安装到本地资源库中.否则maven会到网上去自动下载,这样速度有影响.

记住,第一次运行maven,它要到网上去下载一大堆jar文件.这些jar文件是maven众多的插件所需要的.因此在等待下载的过程中,你有时间去泡杯咖啡了.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有