1. The basic ant script to compile java files in one folder is
<javac srcdir="${src}"
destdir="${build}"
classpath="xyz.jar"
debug="on" />
Above script compiles all .java files under the ${src} directory, and stores the .class files in the ${build} directory. If your code using any thirdparty jars, you need to specify in classpath and and compiling with debug information is on.
2. Ant script to compile java files with some extra logic is
<javac srcdir="${src}"
destdir="${build}"
includes="mypkg/p1/**,mypkg/p2/**"
excludes="mypkg/p1/testpkg/**"
classpath="xyz.jar"
debug="on"/>
Above script compiles .java files under the ${src} directory, and stores the .class files in the ${build} directory. The classpath used includes xyz.jar, and debug information is on. Only files under mypkg/p1 and mypkg/p2 are used. All files in and below the mypkg/p1/testpkg directory are excluded from compilation.
3. Ant script to compile multiple source directories at one shot is
<javac srcdir="${src}:${src2}"
destdir="${build}"
includes="mypkg/p1/**,mypkg/p2/**"
excludes="mypkg/p1/testpkg/**"
classpath="xyz.jar"
debug="on"/>
This can also be represented using nested
<javac destdir="${build}"
classpath="xyz.jar"
debug="on">
<src path="${src}"/>
<src path="${src2}"/>
<include name="mypkg/p1/**"/>
<include name="mypkg/p2/**"/>
<exclude name="mypkg/p1/testpkg/**"/>
</javac>
No comments:
Post a Comment