不知谁能说说ANT的用法?

muly 2001-12-24 05:32:24
...全文
82 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
sharetop 2001-12-25
  • 打赏
  • 举报
回复

给分吧,哥们,我现在穷的很,斑竹地位芨芨可危。
sharetop 2001-12-25
  • 打赏
  • 举报
回复

你安装了ant,就可以看一下他的document了,里面说得很详细了,我一下也说不清也说不完而且我也不是了解的非常多,常用的几个而已。

象上面的:
<!-- set global properties for this build -->
<property name="src" value="."/>
<property name="build" value="build"/>
<property name="dist" value="dist"/>

应该好理解,声明一下源文件所在目录是当前目录,编译目录是build,输出目录是dist,然后初始化
<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>

创建了编译路径。就开始compile了

<target name="compile" depends="init">
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}"/>
</target>

调用javac来实现,源文件在变量${src}指的目录下。然后创建输出目录,并打包.class文件到输出目录下
<target name="dist" depends="compile">
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/>

<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/lib/MyProject.jar" basedir="${build}"/>
</target>

差不多就这样了,你还是自已理解一下吧。





muly 2001-12-25
  • 打赏
  • 举报
回复
是否能将build.xml内容说的再详细一点。谢了!
sharetop 2001-12-24
  • 打赏
  • 举报
回复
说来话长。它就是一个工程管理工具,比如一个最简单的hello world程序吧。

第一步:写程序(不说了吧)

第二步:写build.xml文件。如下:

<project name="MyProject" default="dist" basedir=".">

<!-- set global properties for this build -->
<property name="src" value="."/>
<property name="build" value="build"/>
<property name="dist" value="dist"/>

<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>

<target name="compile" depends="init">
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}"/>
</target>

<target name="dist" depends="compile">
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/>

<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/lib/MyProject.jar" basedir="${build}"/>
</target>

<target name="clean">
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>


第三步:ant 一下,然后会生成如下文件:
G:\SHARE\ant_test_prj\dist\lib\MyProject.jar

这里的屏幕输出如下:
G:\SHARE\ant_test_prj>ant
Buildfile: build.xml

init:

compile:

dist:

BUILD SUCCESSFUL

Total time: 1 second
G:\SHARE\ant_test_prj>

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧