Ant是一个类似make的编译工具。下面用一个最简单也是最经典的例子:HelloWorld 来感受一下Ant吧。
创建HelloWorld.java源文件,放在src子目录下。
package com.sharetop.antdemo;
public class HelloWorld {
public static void main( String args[] ) {
System.out.println("Hello world. ");
}
}
然后,编写一个配置文件build.xml
< ?xml version="1.0" encoding="UTF-8" ?>
<project name="HelloWorld" default="run" basedir="." >
<property name="src" value="src"/>
<property name="dest" value="classes"/>
<property name="hello_jar" value="hello.jar" />
<target name="init">
<mkdir dir="${dest}"/>
</target>
<target name="compile" depends="init">
<javac srcdir="${src}" destdir="${dest}"/>
</target>
<target name="build" depends="compile">
<jar jarfile="${hello_jar}" basedir="${dest}"/>
</target>
<target name="run" depends="build">
<java classname="com.sharetop.antdemo.HelloWorld" classpath="${hello_jar}"/>
</target>
</project>
来看一下这个文件的内容,它描述了以下信息:工程的名字为HelloWorld,工程有四个target,分别是init、compil、 build和 run,缺省是run。compile只有一个任务javac,源文件位于src目录下,输出的类文件要放在classes目录下。build的任务是 jar,生成的jar文件为hello.jar,它打包时以classes为根目录。而run则是执行这个HelloWorld类,用hello.jar 作为classpath。这四个target之间有一个依赖关系,这种关系用depends来指定。即如果Target A依赖于Target B,那么在执行Target A之前会首先执行Target B。所以从下面运行缺省Target(run)的输出看,这四个Target的执行顺序是:init→compile→build→run。
在命令行输入命令:ant,然后运行,可以看到输出结果。
如果配置文件名不是build.xml,比如是mybuild.xml,那么,可以使用-f命令参数指定:
ant -f mybuild.xml</code>
也可以单独执行指定的某个target,比如,只编译不打包执行,可以使用下面输入命令即可:
ant -f mybuild.xml compile
XML文件中也可以打印信息,便于调试。
<echo message="Compile message..."/>
错误提示 解决方法:
ant编译,结果总是提示,我百试不得其解,提示:processing instruction must begin with the name of the target
原来是build.xml里xml的申明在?和xml之间多了个空格.应该是<?xml version = "1.0" encoding = "UTF-8" ?> 而不是 <? xml version = "1.0" encoding = "UTF-8" ?>.
分享到:
相关推荐
使用Ant打包的demo.
#antdemo ##Antroduction antdemo - 蚂蚁演示##执照 Copyright (C) 2013 Snowdream Mobile <yanghui1986527>Licensed under the Apache License, Version 2.0 (the "License");you may not use this file except ...
NULL 博文链接:https://taink.iteye.com/blog/599953
Ant 编译 多目录demo,同时编译多个目录的Ant demo代码。
这里是我的代码的ant打包的demo和反编绎的工具,欢迎下载。
ant design pro 入门demo,包含自己开发的一个组件,供大家参考
ant build.xml demo 供自己及好友学习,能很快上手
apache-ant-1.9.6 demo
Ant脚本打包Android程序的demo(含打包第三方jar)。 build_with_bat是基于bat脚本实现的。 build是在build_with_bat的基础上实现的,主要是在compile和dex部分增加了第三jar的打包。
Vue ant-d 实现面包屑和布局和菜单 demo,里面使用vue+ant-d实现页面布局,面包屑、路由,菜单功能
一个用于weblogic下ant部署的demo。
ant打zip包简单demo,网上看到竟然一个ant包,也要要积分下载,汗死鸟
Android 使用Ant打包 详细地址:http://blog.csdn.net/zxw136511485/article/details/52188840
1.DEMO安装 1.1.前端安装 下载最新的Node 下载GIT并且安装,安装好后用管理员模式执行git-bash.exe VSCODE导入项目: 1.2.后端安装 ...https://3x.ant.design/docs/react/introduce-cn ht
文章地址: https://blog.csdn.net/lxyoucan/article/details/109494901 React 使用Ant Design组件2020年11月
含: apache-ant-1.9.2-bin.zip Ant帮助文档.docx 有文档结构视图,方便查阅 Ant 下载、安装、使用、教程全面了解 - edward0830ly的...3个demo:build.xml自己随便写的,build-wsimport-example.xml,build-ejb-demo
"ant demo.start" 结束后自动打开浏览器访问相 关演示模块的首页。 七)检查一下你的电脑是否已经使用了 tomcat 服务 如果使用了 tomcat 服务, 得停掉, 否测会冲突。 顺便检查一下 8080 端口有没有 被占用,...
ant design demo 直接打开里面Html即可,chrome最佳
Apache Ant 与Junit 对Java工程联合测试DEMO
JUnit+Ant+Jacoco整合 一个小Demo源码,亲测通过,可以作为入门资源。