我在ant
编程中非常新,我制作了一个build.xml
,它仅执行编译文件。但是我现在要学习的是"它应该自动构建.java
文件并将其移至target
文件夹。
目前,我正在汇编Eclipse&将其移至目标文件夹&然后使用ant
运行。
我有一个文件夹结构,例如
Myproject
source
Helloworld.java
target
lib
build.xml
在我的build.xml中,我有以下代码,
<?xml version="1.0" encoding="UTF-8"?>
<project name="Hello World Project" default="info">
<path id="master-classpath"> <fileset dir="lib"> <include name="*.jar"/> </fileset> </path>
<target name="info">
<junit printsummary="yes" haltonfailure="yes">
<classpath>
<pathelement location="target"/>
</classpath>
<classpath refid="master-classpath"/>
<test name="Helloworld" haltonfailure="no" outfile="result">
<formatter type="plain"/>
<formatter type="xml"/>
</test>
</junit>
</target>
</project>
您需要使用 javac
ant任务有点像这样:
<target name="build" description="Compile main source tree java files">
<mkdir dir="target"/>
<javac destdir="target" source="1.6" target="1.6" debug="true"
deprecation="false" optimize="false" failonerror="true">
<src path="src"/>
<classpath refid="master-classpath"/>
</javac>
</target>
您需要将所有依赖罐放在master-classpath
中。
希望这会有所帮助。