`

Ant初体验

    博客分类:
  • Ant
 
阅读更多

 

1.第一个Ant例子(运行版本为1.8.4)

   1)  一个build.xml文件有一个project标签,project的属性default指定默认执行的target。

   2)  project标签中可以有一个description标签对project进行描述。

   3)  project标签可以有多个target标签,target标签属性name指定target的名称,description对target进行描述,depends属性指定target所依赖的target。

   4)  每个target中可以有多个要执行的命令。

 

<?xml version="1.0" encoding="UTF-8"?>
<project name="firstbuild" default="execute">
	
	<description>第一个简单的Build文件</description>

	<target name="init" description="创建项目文件夹">
		<mkdir dir="build/classes"/>
		<mkdir dir="dist"/>
	</target>

	<target name="compile" depends="init" description="编译Java源文件">
		<javac includeAntRuntime="false" srcdir="src" destdir="build/classes"/>
		<echo level="info">compilation complete!</echo>
	</target>

	<target name="archive" depends="compile" description="创建Jar文件">
		<jar destfile="dist/project.jar" basedir="build/classes" />
	</target>

	<target name="clean" description="清除项目文件夹">
		<delete dir="build"/>
		<delete dir="dist"/>
	</target>

	<target name="execute" depends="compile" description="运行项目">
		<java classname="xuj.ant.Main" classpath="build/classes">
			<arg value="c"/>
			<arg value="d"/>
			<arg value="测试"/>
			<arg file="."/>
		</java>
	</target>
</project>

 

 

2.  部分标签属性解释

      echo标签属性level:

          level属性的值可以是:error,warning,info,verbose,debug.默认为 warning

      javac标签属性 includeAntRuntime 

         includeAntRuntime:是否包含Ant中的jar。默认为True。

 

 3.  控制输出信息

          >ant(默认输出日志信息,还装饰内容)

 

>ant
Buildfile: E:\antspace\firstbuild\build.xml

init:
    [mkdir] Created dir: E:\antspace\firstbuild\build\classes
    [mkdir] Created dir: E:\antspace\firstbuild\dist

compile:
    [javac] Compiling 1 source file to E:\antspace\firstbuild\build\classes
     [echo] compilation complete!

execute:
     [java] c
     [java] d
     [java] 测试
     [java] E:\antspace\firstbuild
     [java] 完成!

BUILD SUCCESSFUL
Total time: 1 second

 

          >ant -debug/-d(包含-verbose模式的输出,还包含大量底层的信息,Ant开发人员有兴趣)

 

>ant -debug
Apache Ant(TM) version 1.8.4 compiled on May 22 2012
Trying the default build file: build.xml
Buildfile: E:\antspace\firstbuild\build.xml
Adding reference: ant.PropertyHelper
Detected Java version: 1.6 in: D:\dev\java\jdk16027\jre
Detected OS: Windows 7
Adding reference: ant.ComponentHelper
Setting ro project property: ant.file -> E:\antspace\firstbuild\build.xml
Setting ro project property: ant.file.type -> file
Adding reference: ant.projectHelper
Adding reference: ant.parsing.context
Adding reference: ant.targets
parsing buildfile E:\antspace\firstbuild\build.xml with URI = file:/E:/antspace/
firstbuild/build.xml
Setting ro project property: ant.project.name -> firstbuild
Adding reference: firstbuild
Setting ro project property: ant.project.default-target -> execute
Setting ro project property: ant.file.firstbuild -> E:\antspace\firstbuild\build
.xml
Setting ro project property: ant.file.type.firstbuild -> file
Project base dir set to: E:\antspace\firstbuild
 +Target:
 +Target: init
 +Target: compile
 +Target: archive
 +Target: clean
 +Target: execute
Adding reference: ant.LocalProperties
parsing buildfile jar:file:/D:/dev/ant/ant1.8.4/lib/ant.jar!/org/apache/tools/an
t/antlib.xml with URI = jar:file:/D:/dev/ant/ant1.8.4/lib/ant.jar!/org/apache/to
ols/ant/antlib.xml from a zip file
Setting ro project property: ant.project.invoked-targets -> execute
Attempting to create object of type org.apache.tools.ant.helper.DefaultExecutor
Adding reference: ant.executor
Build sequence for target(s) `execute' is [init, compile, execute]
Complete build sequence is [init, compile, execute, clean, archive, ]

init:
    [mkdir] Created dir: E:\antspace\firstbuild\build\classes
    [mkdir] Created dir: E:\antspace\firstbuild\dist

compile:
fileset: Setup scanner in dir E:\antspace\firstbuild\src with patternSet{ includ
es: [] excludes: [] }
    [javac] E:\antspace\firstbuild\src\xuj\ant\Main.class skipped - don't know h
ow to handle it
    [javac] xuj\ant\Main.java added as xuj\ant\Main.class doesn't exist.
    [javac] E:\antspace\firstbuild\src\xuj\ant\Main.java.bak skipped - don't kno
w how to handle it
    [javac] Compiling 1 source file to E:\antspace\firstbuild\build\classes
    [javac] Using modern compiler
    [javac] Compilation arguments:
    [javac] '-d'
    [javac] 'E:\antspace\firstbuild\build\classes'
    [javac] '-classpath'
    [javac] 'E:\antspace\firstbuild\build\classes'
    [javac] '-sourcepath'
    [javac] 'E:\antspace\firstbuild\src'
    [javac] '-g:none'
    [javac]
    [javac] The ' characters around the executable and arguments are
    [javac] not part of the command.
    [javac] File to be compiled:
    [javac]     E:\antspace\firstbuild\src\xuj\ant\Main.java
     [echo] compilation complete!

execute:
     [java] running xuj.ant.Main with default permissions (exit forbidden)
     [java] Running in same VM Executing 'xuj.ant.Main' with arguments:
     [java] 'c'
     [java] 'd'
     [java] '测试'
     [java] 'E:\antspace\firstbuild'
     [java]
     [java] The ' characters around the executable and arguments are
     [java] not part of the command.
force loading xuj.ant.Main
Finding class xuj.ant.Main
Loaded from E:\antspace\firstbuild\build\classes xuj/ant/Main.class
Class java.lang.Object loaded from parent loader (parentFirst)
Class java.lang.String loaded from parent loader (parentFirst)
Class java.lang.System loaded from parent loader (parentFirst)
Class java.io.PrintStream loaded from parent loader (parentFirst)
     [java] c
     [java] d
     [java] 测试
     [java] E:\antspace\firstbuild
     [java] 完成!

BUILD SUCCESSFUL
Total time: 0 seconds

 

          >ant -verbose/-v(打印冗长的输出,有利于更好地调试)

 

ant -v
Apache Ant(TM) version 1.8.4 compiled on May 22 2012
Trying the default build file: build.xml
Buildfile: E:\antspace\firstbuild\build.xml
Detected Java version: 1.6 in: D:\dev\java\jdk16027\jre
Detected OS: Windows 7
parsing buildfile E:\antspace\firstbuild\build.xml with URI = file:/E:/antspace/
firstbuild/build.xml
Project base dir set to: E:\antspace\firstbuild
parsing buildfile jar:file:/D:/dev/ant/ant1.8.4/lib/ant.jar!/org/apache/tools/an
t/antlib.xml with URI = jar:file:/D:/dev/ant/ant1.8.4/lib/ant.jar!/org/apache/to
ols/ant/antlib.xml from a zip file
Build sequence for target(s) `execute' is [init, compile, execute]
Complete build sequence is [init, compile, execute, clean, archive, ]

init:
    [mkdir] Created dir: E:\antspace\firstbuild\build\classes
    [mkdir] Created dir: E:\antspace\firstbuild\dist

compile:
    [javac] E:\antspace\firstbuild\src\xuj\ant\Main.class skipped - don't know h
ow to handle it
    [javac] xuj\ant\Main.java added as xuj\ant\Main.class doesn't exist.
    [javac] E:\antspace\firstbuild\src\xuj\ant\Main.java.bak skipped - don't kno
w how to handle it
    [javac] Compiling 1 source file to E:\antspace\firstbuild\build\classes
    [javac] Using modern compiler
    [javac] Compilation arguments:
    [javac] '-d'
    [javac] 'E:\antspace\firstbuild\build\classes'
    [javac] '-classpath'
    [javac] 'E:\antspace\firstbuild\build\classes'
    [javac] '-sourcepath'
    [javac] 'E:\antspace\firstbuild\src'
    [javac] '-g:none'
    [javac]
    [javac] The ' characters around the executable and arguments are
    [javac] not part of the command.
    [javac] File to be compiled:
    [javac]     E:\antspace\firstbuild\src\xuj\ant\Main.java
     [echo] compilation complete!

execute:
     [java] running xuj.ant.Main with default permissions (exit forbidden)
     [java] Running in same VM Executing 'xuj.ant.Main' with arguments:
     [java] 'c'
     [java] 'd'
     [java] '测试'
     [java] 'E:\antspace\firstbuild'
     [java]
     [java] The ' characters around the executable and arguments are
     [java] not part of the command.
     [java] c
     [java] d
     [java] 测试
     [java] E:\antspace\firstbuild
     [java] 完成!

BUILD SUCCESSFUL
Total time: 1 second

 

          >ant -emacs(生成日志信息,去掉装饰性的内容)

 

>ant -emacs
Buildfile: E:\antspace\firstbuild\build.xml

init:
Created dir: E:\antspace\firstbuild\build\classes
Created dir: E:\antspace\firstbuild\dist

compile:
Compiling 1 source file to E:\antspace\firstbuild\build\classes
compilation complete!

execute:
c
d
测试
E:\antspace\firstbuild
完成!

BUILD SUCCESSFUL
Total time: 0 seconds

 

          >ant -quiet/-q(运行安静的构建,只打印错误信息,会打印echo标签中level为warning级别以上的信息)

 

>ant -quiet

BUILD SUCCESSFUL
Total time: 1 second

 

3.获取项目信息

 

          >ant -projecthelp/-p(打印关于当前项目的信息)

 

>ant -projecthelp
Buildfile: E:\antspace\firstbuild\build.xml
第一个简单的Build文件
Main targets:

 archive  创建Jar文件
 clean    清除项目文件夹
 compile  编译Java源文件
 execute  运行项目
 init     创建项目文件夹
Default target: execute

 

4.指定要运行的构建文件

 

          >ant -buildfile build.xml

 

>ant -buildfile build.xml
Buildfile: E:\antspace\firstbuild\build.xml

init:
    [mkdir] Created dir: E:\antspace\firstbuild\build\classes
    [mkdir] Created dir: E:\antspace\firstbuild\dist

compile:
    [javac] Compiling 1 source file to E:\antspace\firstbuild\build\classes
     [echo] compilation complete!

execute:
     [java] c
     [java] d
     [java] 测试
     [java] E:\antspace\firstbuild
     [java] 完成!

BUILD SUCCESSFUL
Total time: 1 second

 

5.运行指定目标

 

         >ant clean(这里指运行目标名称为clean的目标)

 

>ant clean
Buildfile: E:\antspace\firstbuild\build.xml

clean:
   [delete] Deleting directory E:\antspace\firstbuild\build
   [delete] Deleting directory E:\antspace\firstbuild\dist

BUILD SUCCESSFUL
Total time: 0 seconds

 

6.运行多个目标

 

          >ant clean execute

 

>ant clean execute
Buildfile: E:\antspace\firstbuild\build.xml

clean:
   [delete] Deleting directory E:\antspace\firstbuild\build
   [delete] Deleting directory E:\antspace\firstbuild\dist

init:
    [mkdir] Created dir: E:\antspace\firstbuild\build\classes
    [mkdir] Created dir: E:\antspace\firstbuild\dist

compile:
    [javac] Compiling 1 source file to E:\antspace\firstbuild\build\classes
     [echo] compilation complete!

execute:
     [java] c
     [java] d
     [java] 测试
     [java] E:\antspace\firstbuild
     [java] 完成!

BUILD SUCCESSFUL
Total time: 1 second

 

 7.-keep-going/-k(当命令行中的一个目标失败后,继续运行其他目标)

>ant execute clean
Buildfile: E:\antspace\firstbuild\build.xml

init:

compile:

BUILD FAILED
E:\antspace\firstbuild\build.xml:12: Problem: failed to create task or type java
ac
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.


Total time: 0 seconds

 

>ant -k execute clean
Buildfile: E:\antspace\firstbuild\build.xml

init:

compile:
Target 'compile' failed with message 'Problem: failed to create task or type jav
aac
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
'.
Cannot execute 'execute' - 'compile' failed or was not executed.

clean:
   [delete] Deleting directory E:\antspace\firstbuild\build
   [delete] Deleting directory E:\antspace\firstbuild\dist

BUILD FAILED
E:\antspace\firstbuild\build.xml:12: Problem: failed to create task or type java
ac
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.


Total time: 0 seconds

 

 

 

分享到:
评论

相关推荐

    AntDesign3.9.x_Axure_20180903.rplib

    AntDesign3.9.x是该框架的一个重要版本,它在保持原有优势的基础上,对组件和交互体验进行了进一步优化。本文将深入探讨AntDesign3.9.x如何在Axure中被高效利用,以及如何通过Axure实现多样的交互设计场景。 首先,...

    拼图小游戏,Java Swing初体验.zip

    标题中的“拼图小游戏,Java Swing初体验”表明这是一个基于Java Swing开发的简易拼图游戏。Java Swing是Java Foundation Classes (JFC)的一部分,用于构建桌面应用的图形用户界面(GUI)。它提供了丰富的组件库,...

    URLClassLoader初体验

    这篇博客文章“URLClassLoader初体验”可能深入探讨了如何使用`URLClassLoader`来动态加载类和资源,以及它在实际开发中的应用。下面我们将详细探讨`URLClassLoader`的相关知识点。 首先,`URLClassLoader`是Java...

    ng-zorro-antd 入门初体验

    ng-zorro-antd是一个基于Angular的Ant Design组件库,它为Angular开发者提供了使用Ant Design风格的UI组件的能力。Ant Design是阿里巴巴开源的一套企业级设计语言和UI组件库,最初是为React设计的。ng-zorro-antd则...

    Salvà, Maria-Antònia_ Viatge a Orient. (Seguit d 'Excursió a

    这次旅行是19世纪末和20世纪初加泰罗尼亚文化代表前往中东地区旅行记述的一部分,尤其是近东地区。 这次特定的朝圣之旅中,还包括了作家佩雷·洛贝拉和他的叔叔米格尔·科斯塔·洛贝拉的参与。他们各自都发表了关于...

    CPSC-335-Langton-s-Ant-Lab

    总的来说,“CPSC-335-Langton-s-Ant-Lab”这个项目不仅提供了学习和实践JavaScript的机会,还让我们有机会亲身体验到简单规则如何产生复杂性的神奇之处。通过参与这个实验,你将能掌握如何用编程语言模拟复杂系统,...

    ant-repo-public

    为所有Spring开发提供根本上更快且可广泛访问的入门体验。 开箱即用,但随着需求开始偏离默认值,您会很快摆脱困境。 提供一系列大型项目通用的非功能性功能(例如嵌入式服务器,安全性,指标,运行状况检查和...

    liferay6.06

    1. Liferay Portal初体验: Liferay Portal是一款功能强大的企业级门户平台,支持多语言、多租户,提供内容管理、社交协作、工作流、个性化等功能。6.0.6版本在稳定性与性能上有所提升,适合开发者和企业进行二次...

    LifeRay_Portal6.0.6学习手册

    1. **LifeRay Portal初体验** LifeRay Portal是一款开源的企业级门户平台,它提供了一个全面的框架来构建、管理和展示各种Web应用程序。初学者在接触LifeRay时,会发现其强大的用户管理、内容管理、社区构建和协作...

    基于J2EE的Ajax宝典.docx

    **第二章 Ajax初体验**中,作者通过一个聊天室的实例展示了Ajax的应用。传统JSP聊天室需要每次新消息到来时整个页面刷新,而采用Ajax技术的聊天室则可以仅更新聊天内容,避免了多余的页面刷新,提高了效率。书中详细...

    Creating Flat Design Websites

    这种设计理念起源于20世纪初的包豪斯运动,强调的是形式和功能的统一。扁平化设计推崇简洁和直接,页面元素的视觉效果采用二维图形,界面的外观更注重设计元素的色彩、形状和布局。 扁平化设计网站的创建涉及到网页...

    799js_HTML手机电脑网站_网页源码移动端前端js效果_H5模板_自适应css源码ui组件.zip

    4. 前端框架与UI组件:前端框架如Bootstrap、Element UI或Ant Design等,提供预设的CSS样式和JavaScript组件,可以快速搭建界面。这些UI组件包括按钮、表单、导航栏、网格系统等,遵循一致的设计规范,大大提高了...

    基于单片机的无线数据收发系统设计与实现.doc

    当用户需要发送数据时,输入的信号通过DIN脚进入芯片,经过内部的调制过程后,通过ANT1或ANT2天线接入端发送出去。当作为接收端时,无线信号通过相同的天线接入端接收,并在芯片内部解调,最后通过DOUT脚将数据输出...

Global site tag (gtag.js) - Google Analytics