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

Ant Build Script

Ant 
阅读更多

<?xml version="1.0" encoding="GB2312" ?>
<!--
=======================================================================
hello-ant 项目 ,学习ant工具的build file.

参照ant的jakarta-ant-1.6alpha的build.xml
=======================================================================
-->

<!--
文档结构为:
<project>
<property/> 全局变量的定义
<property/>...

<target name="1"> 任务组(tasks)
<javac></javac> 一项javac任务
...
<oneTask></oneTask> 一项其它任务
</target>

<target name="2">
<javac></javac>
...
<oneTask></oneTask>
</target>
</project>

project代表一个项目,
default:运行到名称为"dist"的target(任务组)
basedir:基准路径。
-->
<project default="dist" basedir=".">

<!--
===================================================================
定义属性(property tasks)
最好把用到的路径,名称都在这里定义成全局变量
例:定义
<property name="a" value="hello"/>
以后就可以这样用它:
<property name="b" value="${a}/b"/>
现在:b=="hello/b"
===================================================================
-->

<!--主要的系统环境属性-->
<property environment="env"/> <!--取window,unix...的环境变量-->
<property name="java.home" value="${env.JAVA_HOME}"/>
<property name="ant.home" value="${env.ANT_HOME}"/>

<!--主要的app环境属性-->
<property name="app.name" value="hello-ant"/>
<property name="app.jar" value="${app.name}.jar"/>
<property name="app.copyright" value=" Copyright (c) 2002 The Software Foundation. All rights reserved."/>


<!--app中src的属性-->
<property name="src.dir" value="src" />
<property name="src.main" value="${src.dir}/main"/>
<property name="src.script" value="${src.dir}/script"/>

<!--app用到的lib-->
<property name="lib.dir" value="lib"/>

<!--app的build目录中-->
<property name="build.dir" value="build" />
<property name="build.classes" value="${build.dir}/classes"/>
<property name="build.docs" value="${build.dir}/docs"/>
<property name="build.docs.api" value="${build.docs}/api"/>
<property name="build.lib" value="${build.dir}/lib"/>

<!--app的dist (distribution) 目录中-->
<property name="dist.dir" value="dist"/>
<property name="dist.bin" value="${dist.dir}/bin"/>
<property name="dist.docs" value="${dist.dir}/docs"/>
<property name="dist.lib" value="${dist.dir}/lib"/>

<!--app的docs目录中-->
<property name="docs.dir" value="docs"/>

<!--
定义一组路径以后可以通过id重用这组路径 ,例:
<javac srcdir="src/main" destdir="build/classes">
<classpath refid="classpath"/>
</javac>
-->
<path id="classpath">
<!--本项目只有一个java,用不上classpath,这里只是做个例子-->
<pathelement location="${build.classes}"/>
<pathelement path="${java.home}/lib/tools.jar"/>
</path>

<!--
===================================================================
init 准备目录(File Tasks)
主要的目录结构通常是不会变的,一起生成他们
===================================================================
-->
<target name="init">
<!--清除以前目录-->
<delete dir="${build.dir}" failonerror="false" />
<delete dir="${dist.dir}" failonerror="false"/>

<!--准备目录-->
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.classes}"/>
<mkdir dir="${build.docs}"/>
<mkdir dir="${build.docs.api}"/>
<mkdir dir="${build.lib}"/>

<mkdir dir="${dist.dir}"/>
<mkdir dir="${dist.bin}"/>
<mkdir dir="${dist.lib}"/>

</target>

<!--
===================================================================
Build the code (Compile Tasks,File Tasks)
===================================================================
-->
<target name="build" depends="init">
<!--编译-->
<javac srcdir="${src.main}" destdir="${build.classes}">
<classpath refid="classpath"/>
</javac>
</target>

<!--
===================================================================
打包文档(Archive Tasks)
Create the project jars: xxx1.jar and xxx2.jar
===================================================================
-->
<target name="jars" depends="build">
<jar basedir="${build.classes}" jarfile="${build.lib}/${app.jar}"/>
</target>

<!--
===================================================================
Creates the API documentation
===================================================================
-->
<target name="javadocs"
depends="jars"
description="--> creates the API documentation">
<!--copy docs 手册... -->
<copy todir="${build.docs}">
<fileset dir="${docs.dir}"/>
</copy>

<javadoc packagenames="hello.ant.*"
sourcepath="${src.main}"
defaultexcludes="yes"
destdir="${build.docs.api}"
author="true"
version="true"
use="true"
windowtitle="Docs API">
<doctitle><![CDATA[<h1>hello ant Docs API</h1>]]></doctitle>
<bottom><![CDATA[<i>${app.copyright}</i>]]></bottom>
<tag name="todo" scope="all" description="To do:" />
</javadoc>
</target>

<!--
===================================================================
Create the distribution that can run (Archive Tasks)
主要是从各目录中把该copy的copy上
===================================================================
-->
<target name="dist" depends="javadocs">
<!--copy bin 执行文件 -->
<copy todir="${dist.bin}">
<fileset dir="${src.script}/"/>
</copy>
<copy todir="${dist.docs}">
<fileset dir="${build.docs}/"/>
</copy>
<!-- copy lib 文件 -->
<copy todir="${dist.lib}">
<fileset dir="${build.lib}/"/>
</copy>

</target>

</project>

 

demo 1 :
<?xml version="1.0" encoding="UTF-8" ?>
<project name="test-project" default="zip" basedir=".">

<property name="src" value="src" />
<property name="build" value="build\classes" />
<property name="dist" value="dist" />
<property name="lib" value="lib" />
<property name="zip" value="zip" />

<path id="classpath">
<fileset dir="${lib}">
<include name="**/*.jar" />
</fileset>
</path>

<target name="clean">
<delete dir="build" />
<delete dir="${dist}" />
<delete dir="${zip}" />
</target>

<target name="prepare" depends="clean">
<mkdir dir="${zip}" />
<mkdir dir="${build}" />
<mkdir dir="${dist}" />
<mkdir dir="${dist}\lib" />
<mkdir dir="${dist}\config" />
<mkdir dir="${dist}\logs" />
</target>

<target name="compile" depends="prepare" >
<javac srcdir="${src}" destdir="${build}">
<classpath refid="classpath"/>
</javac>
</target>

<target name="jar" depends="compile">
<copy todir="dist\lib">
<fileset dir="lib">
<include name="*.jar" />
<include name="*.zip" />
</fileset>
</copy>

<copy todir="${build}">
<fileset dir="src">
<include name="**/*.xml" />
<include name="**/*.properties" />
</fileset>
</copy>

<copy todir="dist\config">
<fileset dir="config">
<include name="**/*.xml" />
<include name="**/*.properties" />
</fileset>
</copy>

<copy todir="dist">
<fileset dir=".">
<include name="*.bat" />
<include name="tjccQuartzApplication.xml" />
</fileset>
</copy>

<jar jarfile="${dist}\lib\test-project.jar" basedir="${build}"></jar>

</target>

<target name="zip" depends="jar">
<zip basedir="${dist}" destfile="${zip}\test-project.zip"/>
</target>

</project>

demo 2 :

<project name="TaxiServerSocket" default="zip" basedir=".">

<property name="app.name" value="TaxiServerSocket" />
<property name="dir.dist" value="dist" />
<property name="dir.src" value="src" />
<property name="dir.build" value="build/classes" />
<property name="dir.zip" value="zip" />

<path id="classpath">
<fileset file="lib/*.jar" />
<fileset file="lib/*.zip" />
<pathelement path="${dir.build}"/>
</path>

<target name="clean">
<delete dir="${dir.dist}"> </delete>
<delete dir="${dir.build}"> </delete>
<delete dir="${dir.zip}"> </delete>
</target>

<target name="init" depends="clean">
<mkdir dir="${dir.build}"/>
<mkdir dir="${dir.zip}"> </mkdir>
<mkdir dir="${dir.dist}"></mkdir>
<mkdir dir="${dir.dist}/lib" />
<mkdir dir="${dir.dist}/conf" />
<mkdir dir="${dir.dist}/logs" />
</target>

<target name="compile" depends="init" >
<javac srcdir="${dir.src}" destdir="${dir.build}" target="1.6" source="1.6" encoding="UTF-8" debug="true">
<classpath refid="classpath"/>
</javac>
<copy todir="${dir.build}" flatten="false">
<fileset dir="${dir.src}">
<include name="**/*.xml" />
<include name="**/*.properties" />
<include name="**/*.txt" />
</fileset>
</copy>
</target>

<target name="jar" depends="compile">
<jar jarfile="${dir.zip}/taxiposserver.jar" basedir="${dir.build}"></jar>
<copy file="${dir.zip}/taxiposserver.jar" todir="./lib/" />
</target>

<target name="zip" depends="jar">
<copy todir="./dist/lib/">
<fileset dir="lib">
<include name="*.jar" />
<include name="*.zip" />
</fileset>
</copy>

<copy todir="./dist/conf/">
<fileset dir="conf">
<include name="**/*.xml" />
<include name="**/*.conf" />
</fileset>
</copy>

<copy todir="./dist/">
<fileset dir=".">
<include name="*.bat" />
<include name="*.sh" />
</fileset>
</copy>

<zip basedir="${dir.dist}" destfile="${dir.zip}/TaxiServerSocket.zip"/>

</target>

</project>

demo 3 :

<?xml version="1.0"?>
<project name="test-project3" default="pack">
<!-- properies -->
<property name="src.dir" value="src" />
<property name="classes.dir" value="WebRoot/WEB-INF/classes" />
<property name="webroot" value="WebRoot" />
<property name="lib.dir" value="WebRoot/WEB-INF/lib" />
<property name="dist.dir" value="dist" />

<!-- 定义classpath -->
<path id="master-classpath">
<fileset file="${lib.dir}/*.jar" />
<fileset file="${lib.dir}/*.zip" />
<pathelement path="${classes.dir}"/>
</path>

<!-- 初始化任务 -->
<target name="init">
</target>

<!-- 编译 -->
<target name="compile" depends="init" description="compile the source files">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}" target="1.6" source="1.6" encoding="GBK" debug="true" >
<classpath refid="master-classpath"/>
</javac>
<copy todir="${classes.dir}" flatten="false">
<fileset dir="${src.dir}">
<include name="**/*.xml" />
<include name="**/*.properties" />
<exclude name="**/*.java" />
</fileset>
</copy>
</target>

<!-- 打包成war -->
<target name="pack" depends="prepare,compile" description="make .war file">


<mkdir dir="${dist.dir}" />
<war destfile="${dist.dir}/taxi.war" basedir="${webroot}" webxml="WebRoot/WEB-INF/web.xml">
</war>
</target>

<target name="prepare" depends="init" description="拷贝所有文件到源文件到打包路径下">
<delete>
<fileset file="${dist.dir}.war" />
</delete>
</target>

</project>

 

 

 

 

 

分享到:
评论

相关推荐

    ant build script

    NULL 博文链接:https://nethub2.iteye.com/blog/2023197

    Generic Ant Build Script for Java-开源

    运行“ ant -p”以获取潜在目标的完整列表。 预期目标应该是“ jar”,“ war”或“ deploy”。 还有一个名为“ cibuild”的附加任务,旨在与构建服务器一起运行。 除非调用此任务,否则所有构建的文件都将具有...

    DWR2项目实践 用例源代码(2)

    由于比较大分包压缩:总计...use the Ant build script found in xxxx/WEB-INF/src, where xxxx is the name of the webapp. Please note that the exploded webapp IS NOT ready to go as-is, it has to be compiled

    DWR2项目实践 用例源代码(3)

    由于比较大分包压缩:总计...use the Ant build script found in xxxx/WEB-INF/src, where xxxx is the name of the webapp. Please note that the exploded webapp IS NOT ready to go as-is, it has to be compiled

    DWR2项目实践 用例源代码(4)

    由于比较大分包压缩:总计...use the Ant build script found in xxxx/WEB-INF/src, where xxxx is the name of the webapp. Please note that the exploded webapp IS NOT ready to go as-is, it has to be compiled

    DWR2项目实践 用例源代码(5)

    由于比较大分包压缩:总计...use the Ant build script found in xxxx/WEB-INF/src, where xxxx is the name of the webapp. Please note that the exploded webapp IS NOT ready to go as-is, it has to be compiled

    DWR2项目实践 用例源代码(1)

    由于比较大分包压缩:总计...use the Ant build script found in xxxx/WEB-INF/src, where xxxx is the name of the webapp. Please note that the exploded webapp IS NOT ready to go as-is, it has to be compiled.

    最流行的web开发前端模版HTML5 Boilerplate.zip

    这个小小的源码包集合了100位开发者的经验,你可以将这些经验运用在你的项目中。... 还有几个单独维护的项目:server configs, node build script, 和ant build script.     标签:前端模版

    jmeter所需ant执行脚本

    配合ant使用,可以让jmeter飞起来,文件中对生成的文件进行了备份归档整理,同时调用两个测试报告模版,让功能更加强大

    Android代码-phonegap-android

    PhoneGap Android PhoneGap Android is an Android ...Apache ANT (For build script) Ruby, Rubygems, nokogiri (for build.rb) Recommended: Eclipse (Recommended for back-end debugging, not required) G

    安卓多线程

    # To customize properties used by the Ant build system edit # "ant.properties", and override values to adapt the script to your # project structure. # # To enable ProGuard to shrink and obfuscate your...

    ant.js:停止维护, 请使用 https

    ant.jsAnt.js 为 HTML 提供了一种轻量简便的数据绑定方式.Buildgit clone https://github.com/antjs/ant.js.gitcd ant.js && npm installgrunt buildTest用浏览器打开 test\index.html 进行浏览器端测试运行 grunt ...

    The Definitive ANTLR 4 Reference

    Programmers run into parsing problems all the time. Whether it's a data format like JSON, a network protocol like SMTP, a server ... Ant build system optional (needed for building ANTLR from source)

    Gradle in Action

    Build script essentials Chapter 5. Dependency management Chapter 6. Multiproject builds Chapter 7. Testing with Gradle Chapter 8. Extending Gradle Chapter 9. Integration and migration Part 3: From ...

    Red5的MetaDataGenerator

    ant build - will compile the MetaDataGenerator application. ant start - will start the MetaDataGenerator tool, it will first ask to input the path to the flv files. start.sh /path/to/flv - shell ...

    camunda-script-deployment

    您还可以使用ant构建示例并将其部署到应用程序服务器。 为此,您需要将文件build.properties.example复制到build.properties并在其中配置应用程序服务器的路径。 或者,您也可以将其复制到${user.home}/.camunda/...

    maven-and-osgi

    Maven is a new project management and ... Using Maven, you can leverage the experience of the community to avoid the tedious process of creating yet another build script for each new project.

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

    Maven is a new project management and ... Using Maven, you can leverage the experience of the community to avoid the tedious process of creating yet another build script for each new project.

    jenkins常用插件包

    Ant Apache HttpComponents Client 4.x API Plugin Bootstrap 4 API Plugin Bootstrap 5 API bouncycastle API Branch API Build Timeout Caffeine API Plugin Checks API plugin Command Agent Launcher Plugin ...

Global site tag (gtag.js) - Google Analytics