When Ant is used, the third-party Jar package cannot be compiled because the project references a third-party Jar package. You can add the following elements to the Ant script to reference the third-party library.
Steps:
1. Add sub-elements to the <project> element of build. xml, as follows:
<path id="lib_classpath">
<fileset dir="WebContent/WEB-INF/lib/">
<include name="*.jar"/>
</fileset>
</path>
Note: change it to your own Lib path.
2. Add a child element <classpath> to your <target> child element <javac> as follows:
<classpath refid="lib_classpath"/>
A complete example:
<Project name = "JarLibProject" basedir = "." default = "all">
<! -- Property name = "build. compiler" value = "jikes"/>
<Property name = "build. compiler. emacs" value = "true"/-->
<Property name = "build. dir" value = "classes"/>
<Property name = "dist. dir" value = "dist"/>
<Property name = "logdir" value = "logs"/>
<Property name = "source. dir" value = "src"/>
<Property name = "junit. results" value = "test-results"/>
<Property name = "cvs. repository" value = "Your CVSROOT"/>
<Property name = "cvs. package" value = "JarLibProject"/>
<Path id = "lib_classpath">
<! -- Pathelement location = "$ {basedir} \ jar \ httpmime-4.1.1.jar"/>
<Pathelement location = "$ {basedir} \ jar \ signpost-commonshttp4-1.2.1.1.jar"/>
<Pathelement location = "$ {basedir} \ jar \ signpost-core-1.2.1.1.jar"/>
<Pathelement location = "$ {basedir} \ jar \ Analytics-Android-SDK-2.1.jar2"/-->
<Fileset dir = "WebContent/WEB-INF/lib/">
<Include name = "*. jar"/>
</Fileset>
</Path>
<Target name = "init" description = "Prepare for build">
<Mkdir dir = "$ {build. dir}"/>
<Mkdir dir = "$ {dist. dir}"/>
<Mkdir dir = "$ {logdir}"/>
</Target>
<Target name = "clean" description = "Clean all build products">
<Delete dir = "$ {build. dir}"/>
<Delete dir = "$ {dist. dir}"/>
<Mkdir dir = "$ {build. dir}"/>
<Mkdir dir = "$ {dist. dir}"/>
</Target>
<Target name = "compile" depends = "init" description = "Compile application without cleaning">
<Javac srcdir = "$ {source. dir}" destdir = "$ {build. dir }"
Includes = "**/*. java" debug = "true" deprecation = "true">
<Classpath refid = "lib_classpath"/>
</Javac>
</Target>
<Target name = "test" depends = "init" description = "Run unit tests">
<Delete dir = "$ {junit. results}"/>
<Mkdir dir = "$ {junit. results}"/>
<Junit fork = "yes" haltonfailure = "yes">
<Classpath>
<Pathelement location = "$ {build. dir}"/>
</Classpath>
<Formatter type = "plain" usefile = "false"/>
<Formatter type = "xml"/>
<Batchtest todir = "$ {junit. results}">
<Fileset dir = "$ {build. dir}" includes = "**/* Test. class"/>
</Batchtest>
</Junit>
</Target>
<Target name = "jar">
<Jar jarfile = "$ {dist. dir} \ JarLibProject. jar">
<Fileset dir = "$ {build. dir}"/>
</Jar>
</Target>
<Target name = "all" depends = "init, clean, compile, test, jar" description = "Build application"/>
<Target name = "checkout" description = "Update package from CVS">
<Cvs cvsroot = "$ {cvs. repository}" package = "$ {cvs. package}" dest = "..."/>
</Target>
<Target name = "masterbuild" depends = "checkout, compile, test, jar"
Description = "Cruise control master build"/>
<Target name = "cleanbuild" depends = "clean, masterbuild" description = "Cruise control clean build"/>
</Project>