`
javasee
  • 浏览: 960497 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

编写build.xml的12个原则

阅读更多

我不喜欢这个title的翻译,它的原文应该是“通往build.xml天堂的12条路”。为了让读者更容易理解,我最后还是选择了这个通俗……俗气的title。需要注意的是,这篇weblog来自“fate”hani……

12 paths to build.xml nirvana

1 - Always provide shell launchers for ant. A standalone build.xml is simply too demanding for developers, who are used to luxuries like build.bat and build.sh. Nothing says 'we care about your platform' like shell script launchers.

2 - While you're writing those launchers, make sure you provide specialized ones so users can very easy call various build targets. Build.sh looks naked and sad without its childhood friends, make.sh, compile.sh, docs.sh, and run.sh.

3 - Never place your build.xml file in your top level directory. The deeper in it is, the more likely it is that people will actually look at your stuff in a hopeless effort to find said file.

4 - Never allow for people to customize the build process. Sourcing an external properties file is just cause for confusion and trauma.

5 - If you do want customization, then force users to define env vars. Since every user's environment is unique and specific, why not demand and expect them to define 12 *_HOME type variables first? That way when they do get the build going, they'll feel it's like a personal customized version that is tailored for their own needs and nobody else's.

6 - Never rely on -projecthelp. The default ant target should do nothing but spit out a few pages of useless info explaining all the available targets. Yes, ant does allow for this via the -projecthelp switch, but that assumes users know when they need help. It is obvious to you, almighty developer, that unless they explicitly ask for something else, they want help.

7 - Your default target should try to surprise and amuse users. Why have a target that just builds your project when instead you can have it build a whole distribution? Sure, builders are those who might well poke about the source and want quick builds via ant, but screw them. A whole distribution just looks so much more professional.

8 - Ask users to prove their loyalty and dedication to your cause by demanding they add jar files to ANT_HOME/lib. For extra points, do not tell them what these jar files are. It can be a test of the true faithful to see if they can figure it out from an ant stacktrace and find out what jar to download from where.

9 - Never ship dependent jars. As any true maven asshat knows, jars should be delivered over the network from a central repository. This way you can automatically weed out those pesky enterprise users behind restrictive firewalls who are in all likelihood violently opposed to opensores anyway. Make liberal use of the get task, it's there for a reason you know.

10 - Ensure a fresh start! Every target should depend on the clean target. This way you can be sure that the user will not have any problems with left over cruft from an old build. Sure, their build rate will slow down by a few orders of magnitude, but it's better to be safe than sorry.

11 - build.xml should be your gateway to everything. Don't be fooled by its name, you can and should use it to run your apps too. Why bother with pesky manifests and cumbersome jar files? They're from the evil un-free empire of Sun, so you must shun them. Instead, make liberal use of the java task in ant. Real build.xml love will shine through the next time you type ant run.

12 - Consolidation is for the weak. A single buildfile basically screams out 'I'm a girl and like bunnies and wear pink fluffy dresses'. If you're going for a more manly effect, then split your build.xml files into as many pieces as possible. Extra points for bragging about reusability and employing cunning task obfuscation. The casual user must never be able to figure out what is actually going on, or they'll get funny ideas that they could have done it themselves.

分享到:
评论

相关推荐

    Ant_的最完整build.xml解释,Ant入门与进阶

    1. 创建Java项目:从创建源代码目录结构,到编写build.xml,再到执行编译、测试和打包的全过程。 2. 集成测试:如何配置JUnit任务进行单元测试,以及如何集成其他测试框架。 3. 自动化部署:利用Ant实现自动部署到...

    apache-ant

    - 编写`build.xml`文件,定义项目的构建步骤,如`<target>`、`<compile>`、`<jar>`等元素。 - 在命令行中运行`ant [target]`,其中`target`是构建文件中的特定目标,如果不指定,默认执行default目标。 3. **主要...

    Ant使用工具

    一个典型的Ant构建文件`build.xml`分为几个主要部分: 1. **项目声明(Project)**:文件的开头定义了项目的基本属性,如项目名称、默认目标等。 ```xml <project name="MyProject" default="build" basedir="."> `...

    App自动化之使用Ant编译项目多渠道打包[定义].pdf

    在项目结构中,通常有一个名为`build.xml`的Ant脚本文件,它定义了构建过程中的各个任务。对于多工程的项目,例如上面提到的`world`项目,包含一个基础Android Library(`baseworld`)和四个Android Project(`...

    JNSP (java network service platform)

    5. 可以编写一个客户端 DriverClient 来驱动整个流程,可以采用这个方式启动 java -classpath ./:./bin/:/home/huangzheng/MyTest/pack/nioserver.jar:/home/huangzheng/MyTest/pack/lib/log4j-1.2.15.jar -client -...

    一个推箱子游戏,由java编写.zip

    虽然没有具体给出,但通常会包含以下部分:源代码文件(.java),编译后的字节码文件(.class),资源文件(如图像、音频、地图配置文件),以及可能的构建脚本(如Maven的pom.xml或Gradle的build.gradle)。...

    ant使用,java自动化工具

    - 创建`build.xml`:根据项目需求编写构建脚本。 - 运行Ant:在命令行中,通过`ant [target]`来执行目标任务,如果没有指定目标,则默认执行`default`目标。 6. **Ant与Maven的比较** - 虽然Ant提供了高度的灵活...

    ssh框架案例

    5. **运行和构建脚本**:如build.xml(Ant)或pom.xml(Maven),用于项目的构建和部署。 学习这个SSH框架案例,开发者能够深入理解Java Web开发中的MVC架构,熟练掌握SSH框架的使用,并了解如何在实际项目中整合这...

    ssm的maven项目和ssm的web项目

    这样的项目可能包含自定义的构建脚本,如`build.xml`(Ant)或`build.gradle`(Gradle)。 对比两个项目,Maven项目的优势在于标准化和自动化,它可以减少构建错误,使得团队协作更加顺畅。而非Maven项目可能更适合...

    maven相关项目的示例

    - 自定义插件配置:在POM.xml中,可以通过<build><plugins>...</plugins></build>部分配置插件参数。 5. Maven的多模块项目: - 对于大型项目,可以将项目划分为多个子模块,每个子模块都有自己的POM.xml,顶层...

    maven配置.zip

    标题"Maven配置"涉及到的核心内容包括Maven的安装与环境配置、POM.xml文件的理解与编写、本地仓库的设置以及Maven的全局配置等。 1. Maven的安装与环境配置: Maven的安装通常涉及下载最新版本的Maven,解压到指定...

    J2EE OA项目开发日记

    而模块或组件目录下的`build.xml` 是局部配置,针对特定模块或组件,开发者只需调整相应的时间戳和项目特定的变量如`ProjectName`和`componentName`。 2. **编码规范**: - 项目遵循严格的编码规范,包括Java和JSP...

    maven学习配置安装

    3. **编写POM.xml**: 编写POM.xml文件,定义项目信息和依赖。 **六、Maven的常用命令** 1. `mvn clean`: 清理项目生成的目标文件。 2. `mvn compile`: 编译源代码。 3. `mvn test`: 运行单元测试。 4. `mvn package...

    一个公开的java项目.zip

    这个Java项目可能使用了Maven或Gradle等构建工具,它们的配置文件(如pom.xml或build.gradle)会列出项目的依赖关系和构建步骤。如果项目是Web应用,可能会有"web.xml"作为部署描述符,或者Spring Boot应用会有一个...

    Ant 入门讲解视频

    - **创建build.xml**:根据项目需求编写构建文件,定义目标和任务。 - **运行Ant**:在命令行输入`ant`命令,Ant会读取当前目录下的`build.xml`文件并执行默认目标。若需要执行特定目标,可以指定`ant -f build....

    springboot+mybatis的项目

    1. 添加MyBatis和MyBatis-Spring-Boot-Starter依赖到`pom.xml`或`build.gradle`文件。 2. 配置MyBatis的主配置文件`mybatis-config.xml`,定义数据源、事务管理器等。 3. 创建Mapper接口,每个接口对应数据库中的一...

    ant-robotframework-0.2.jar.zip

    Ant通过XML文件(通常称为build.xml)定义任务和依赖关系,使得开发者可以自定义构建流程。"ant-robotframework-0.2.jar"这个文件是Ant的一个扩展,它集成了Robot Framework,使得Ant能够在构建过程中执行Robot ...

    基于SSH的学生成绩管理系统源码.zip

    6. **Maven或Gradle构建文件**:如pom.xml或build.gradle,用于项目的构建和依赖管理。 综合以上信息,我们可以理解到,这个项目是一个使用SSH框架开发的学生成绩管理系统,涵盖了用户认证、成绩管理等多个功能,...

    java automation test

    4. **build.xml**: 这是一个Ant构建文件,Ant是Java项目常用的构建工具,用于编译、打包和测试项目。在自动化测试中,它可能包含了编译测试代码、运行测试和生成测试报告的任务。 5. **bin**: 这个目录通常存放编译...

Global site tag (gtag.js) - Google Analytics