这个build.xml是要你自己写的,没这个你怎么build呀。
一个小例子:
目的:开发一个java类,并用ANT完成编译和运行工作。
步骤:
1。自己在C:\ apache-ant-1.5.4下新建以下目录:
hello-ant
——build
——classes
——src
——main
——hello
——ant
2。在hello-ant/src/main/hello/ant/下新建HelloAnt.java文件
package hello.ant;public class HelloAnt{
public static void main(String[] args){
System.out.println("hello ant,ant 的第一次接触,好棒!");
}
}
3。在hello-ant/下新建build.xml文件
<?xml version="1.0" encoding="GB2312" ?><!-- 一个项目,可包含很多任务组(target) -->
<project default="main" basedir="."> <!-- 项目中的一个任务组,可包含很多任务(task:javac,java...) -->
<target name="main">
<!--编译-->
<javac srcdir="src\main\hello\ant" destdir="build\classes"/>
<!--运行-->
<java classname="hello.ant.HelloAnt">
<classpath>
<pathelement path="build\classes"/>
</classpath>
</java>
</target></project>
4。运行ant
进入build.xml所在目录,执行以下操作:
执行: %ant_home%/bin/ant -file build.xml 用ant工具执行当前目录下的配置文件build.xml
或 :ant -file build.xml 你如果设置%ant_home%/bin到path中
5。结果显示
D:\temp\hello-ant>ant -file build.xml //我们输入运行ant的命令
Buildfile: build.xmlmain:
[javac] Compiling 1 source file to D:\temp\hello-ant\build\classes
[java] hello ant,ant 的第一次接触,好棒!BUILD SUCCESSFUL
Total time: 2 secondsD:\temp\hello-ant>
此时可以发现,在build/classes目录下,出现了编译过的文件HelloAnt.class:
build/classes/hello/ant/HelloAnt.class.
一个小例子:
目的:开发一个java类,并用ANT完成编译和运行工作。
步骤:
1。自己在C:\ apache-ant-1.5.4下新建以下目录:
hello-ant
——build
——classes
——src
——main
——hello
——ant
2。在hello-ant/src/main/hello/ant/下新建HelloAnt.java文件
package hello.ant;public class HelloAnt{
public static void main(String[] args){
System.out.println("hello ant,ant 的第一次接触,好棒!");
}
}
3。在hello-ant/下新建build.xml文件
<?xml version="1.0" encoding="GB2312" ?><!-- 一个项目,可包含很多任务组(target) -->
<project default="main" basedir="."> <!-- 项目中的一个任务组,可包含很多任务(task:javac,java...) -->
<target name="main">
<!--编译-->
<javac srcdir="src\main\hello\ant" destdir="build\classes"/>
<!--运行-->
<java classname="hello.ant.HelloAnt">
<classpath>
<pathelement path="build\classes"/>
</classpath>
</java>
</target></project>
4。运行ant
进入build.xml所在目录,执行以下操作:
执行: %ant_home%/bin/ant -file build.xml 用ant工具执行当前目录下的配置文件build.xml
或 :ant -file build.xml 你如果设置%ant_home%/bin到path中
5。结果显示
D:\temp\hello-ant>ant -file build.xml //我们输入运行ant的命令
Buildfile: build.xmlmain:
[javac] Compiling 1 source file to D:\temp\hello-ant\build\classes
[java] hello ant,ant 的第一次接触,好棒!BUILD SUCCESSFUL
Total time: 2 secondsD:\temp\hello-ant>
此时可以发现,在build/classes目录下,出现了编译过的文件HelloAnt.class:
build/classes/hello/ant/HelloAnt.class.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货