使用Ant打印一句话
1.最简单的打印方法
新建build.xml文件,在该文件输入一下内容:
<project default="main target" name="first project">
<target name="main target">
<echo>this is my firt ant print msg</echo>
</target>
</project>
定位到build.xml文件所在的目录,在控制台下执行:
ant或 ant -buildfile build.xml
第二种方法有点繁琐,现在修改build.xml文件的名字为build2.xml再次执行
如果ant的build信息保存到build.xml文件时,简单的ant就ok了,如果没有,就需要ant -buildfile fileName来指定build文件了。
2.使用批处理文件来执行ant命令
将build2.xml文件名,修改为build.xml,在同一目录下,新建文件,输入一下内容:
ant
然后将文件名修改为startBuild.bat
在控制台执行:startBuild
3.在控制台指明要执行的taget
修改build.xml文件的内容如下:
<project default="main target" name="first project">
<target name="main target">
<echo>execute main target</echo>
</target>
<target name="secondTarget">
<echo>execute second target</echo>
</target>
</project>
分别执行一下命令:
ant
ant secondTarget
使用Ant编译执行一个简单的项目
1.新建一个文件AntBuildProject,其下内容有:
其中compiled文件夹是空白的,用于放置编译后的class文件
2.在AntBuildProjectDemo\src\com\example\antbuildproject下创建Main.java,其代码如下:
package com.example.antbuildproject;
public class Main {
public static void main(String[] args) {
System.out.println("hello,world!");
}
}
3.编写build.xml文件,其内容如下:
<project default="run" name="ant build project">
<target name="run" depends="compile">
<java classname="com.example.antbuildproject.Main">
<classpath path="compiled"></classpath>
</java>
</target>
<target name="compile">
<javac includeantruntime="false" srcdir="./src" destdir="compiled" />
</target>
</project>
定位到build.xml文件所在的目录,在控制台下执行:
ant
翻译地址:
https://www.youtube.com/watch?v=RjTsLEGl238