hOW can i add external jars in my build.xml - ant

hOW can i add external jars in my build.xml.
i am getting compilation error while running my build.xml.some jars are missing.how can i add them in my build.xml.
my build.xml looks like this
<project name="HUDSONSTATUSWS" default="dist" basedir=".">
<description>
Web Services build file
</description>
<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<property name="webcontent" location="WebContent"/>
<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>
<target name="compile" depends="init"
description="compile the source " >
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}"/>
</target>
<target name="dist" depends="compile"
description="generate the distribution" >
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/>
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/>
</target>
<target name="war" depends="compile"
description="generate the distribution war" >
<!-- Create the war distribution directory -->
<mkdir dir="${dist}/war"/>
<!-- Follow standard WAR structure -->
<copydir dest="${dist}/war/build/WEB-INF/" src="${webcontent}/WEB-INF/" />
<copydir dest="${dist}/war/build/WEB-INF/classes/" src="${build}" />
<jar jarfile="${dist}/war/HelloWorld-${DSTAMP}.war" basedir="${dist}/war/build/"/>
</target>
<target name="clean"
description="clean up" >
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>

You just need to specify the classpath for javac, using the classpath or classpathref attribute, or a nested classpath element.
See http://ant.apache.org/manual/Tasks/javac.html for details. The ant documentation is very well written, exhaustive, and full of examples. It's there to be read.

Related

Ant script fails to detect the javafx classes when compiling

I am using the Ant script to compile my source code. previously it was compiling perfectly . recently i added classes which uses javafx specific classes .after this ant is not compiling and it fails to find the javafx classes . i am using jdk 7 update 23 as javafx is inculded in the jdk, i cannot figure out why compilation fails ?.
below is my ant script.
<?xml version="1.0" encoding="UTF-8" ?>
<project name="client" basedir="." default="compile" >
<description>Client</description>
<property file="build.properties" />
<path id="classpath">
<fileset dir="${lib.dir}" includes="*.*"/>
</path>
<!-- Initialization -->
<target name="init" description="Prepare needed directories.">
<mkdir dir="${build.dir}" />
<mkdir dir="${classes.dir}" />
<mkdir dir="${jar.dir}" />
<mkdir dir="${dist.dir}" />
</target>
<!-- Cleanup -->
<target name="clean" description="Remove all files created by the build/test process.">
<delete dir="${classes.dir}" />
<delete dir="${dist.dir}" />
<delete dir="${build.dir}" />
</target>
<!-- Compile application -->
<target name="compile" depends="init" >
<mkdir dir="${classes.dir}"/>
<javac source="1.7" target="1.7" srcdir="${src.dir}" destdir="${classes.dir}" debug="yes" includeantruntime="false" fork="true" memorymaximumsize="1200m" >
<classpath refid="classpath" />
</javac>
</target>
<path id="lib.lib">
<fileset dir="../lib">
<include name="**/*"/>
</fileset>
</path>
<pathconvert property="mf.classpath" pathsep=" lib/">
<path refid="lib.lib"/>
<flattenmapper/>
</pathconvert>
<!-- Java Archive -->
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/Client.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Class-Path" value="lib/${mf.classpath}"/>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</jar>
</target>
</project>
Suggested Solution
If you want to use ant with JavaFX, you should use Oracle's JavaFX ant tasks.
The JavaFX runtime is included with Java 7 and the Oracle JavaFX ant tasks are aware of it's location, so when you use the Oracle ant tasks, builds of projects referencing JavaFX work.
Why your current build fails
Compilation fails for your script because the JavaFX runtime (jfxrt.jar) is not on the default class path for Java 7.
For Java 8 the JavaFX runtime is on the class path.
You can still use plain ant without the Oracle JavaFX ant tasks to build your application (just by ensuring jfxrt.jar is on the class path for your build step), however use of the Oracle tasks is recommended as they will also appropriately package your application for distribution.
See also: Compile code using JavaFX 2.0 (using command line)

Build a Jenkins plugin with Ant

My company only uses Ant to build projects. However, Jenkins only suggests Maven as a build tool for plugin development.
How could I package my Jenkins plugin to a .hpi file using Ant and avoiding Maven at all costs?
Here is a way to build a Jenkins plugin using Ant. Let's make a script that builds a plugin skeleton which name is "awesome".
Default plugin arborescence
awesome-plugin/
-- awesome/
-- src/
-- pom.xml
Instructions
Add a lib/ folder which contains the following jars:
to be found in your Jenkins home directory Jenkins\war\WEB-INF\lib (note: you have to use the exact same versions that your current Jenkins use):
access-modifier-annotation-1.4.jar
bridge-method-annotation-1.4.jar
commons-io-1.4.jar
guava-11.0.1.jar
jenkins-core-1.513.jar
json-lib-2.4-jenkins-1.jar
remoting-2.23.jar
sezpoz-1.9.jar
stapler-1.207.jar
to be found on the web (you can choose the last version released):
servlet-api-2.4.jar
Replace the existing pom.xml with the following build.xml.
In the Ant script, you should adapt:
the project name, awesome here,
the plugin version,
the Jenkins version this plugin is made for,
the project group.id (main package), org.jenkinsci.plugins.awesome here.
New plugin arborescence
awesome-plugin/
-- awesome/
-- src/
-- lib/
-- you should have 10 jars here
-- build.xml
build.xml
<!-- Project dependent properties -->
<property name="project_name" value="awesome"/>
<property name="project_version" value="1.0"/>
<property name="jenkins_version" value="1.513"/> <!-- which version of Jenkins is this plugin built against? -->
<property name="project_groupid" value="org.jenkinsci.plugins.awesome"/>
<!-- Build properties -->
<property name="lib_dir" value="./lib"/>
<property name="bin_dir" value="./bin" />
<property name="target_dir" value="./target"/>
<property name="target_bin_dir" value="${target_dir}/${project_name}"/>
<property name="plugin_targetMetaInf_dir" value="${target_bin_dir}/META-INF"/>
<property name="plugin_targetWebInf_dir" value="${target_bin_dir}/WEB-INF"/>
<property name="plugin_targetWebInfBin_dir" value="${plugin_targetWebInf_dir}/classes"/>
<!-- Project paths -->
<path id="project.source.path">
<pathelement path="src/main/java" />
</path>
<path id="project.class.path">
<fileset dir="${lib_dir}" includes="*.jar"/>
</path>
<!-- Build flow -->
<target name="build">
<antcall target="clean" />
<antcall target="compile" />
<antcall target="createTreeDirectory" />
<antcall target="copyBin"/>
<condition property="has_file">
<and>
<available file="${target_dir}/${project_name}.hpi" type="file"/>
</and>
</condition>
<antcall target="createHpi"/>
<condition property="has_dir">
<and>
<available file="${target_bin_dir}" type="dir"/>
</and>
</condition>
<antcall target="cleanTargetDirectory" />
</target>
<!-- Cleans existing binaries -->
<target name="clean">
<delete includeEmptyDirs="true" quiet="true">
<fileset dir="${bin_dir}" />
</delete>
<mkdir dir="${bin_dir}"/>
</target>
<!-- Compiles JAVA code -->
<target name="compile">
<javac includeantruntime="false" destdir="${bin_dir}" debug="false" optimize="${optimize}" deprecation="${deprecation}" classpathref="project.class.path">
<src refid="project.source.path" />
</javac>
</target>
<!-- Creates necessary target folders -->
<target name="createTreeDirectory" >
<mkdir dir="${target_bin_dir}"/>
<mkdir dir="${plugin_targetMetaInf_dir}"/>
<mkdir dir="${plugin_targetWebInf_dir}"/>
<mkdir dir="${plugin_targetWebInfBin_dir}"/>
</target>
<!-- Moves new binaries to the plugin target -->
<target name="copyBin">
<copy todir="${plugin_targetWebInfBin_dir}" >
<fileset dir="${bin_dir}"/>
<fileset dir="src/main/resources"/>
</copy>
</target>
<!-- Cleans the target directory -->
<target name="cleanTargetDirectory" if="has_dir">
<delete dir="${target_bin_dir}"/>
</target>
<!-- Backup previous plugin -->
<target name="saveOldHpiFile" if="has_file">
<move file="${target_dir}/${project_name}.hpi" tofile="${target_dir}/${project_name}.save.hpi"/>
</target>
<!-- Archives the plugin -->
<target name="createHpi">
<antcall target="saveOldHpiFile"/>
<jar destfile="${target_dir}/${project_name}.hpi" basedir="${target_bin_dir}">
<manifest>
<attribute name="Manifest-Version" value="{project_version}"/>
<attribute name="Built-By" value="${user.name}"/>
<attribute name="Created-By" value="${user.name}"/>
<attribute name="Build-Jdk" value="${ant.java.version}"/>
<attribute name="Extension-Name" value="${project_name}"/>
<attribute name="Implementation-Title" value="${project_name}"/>
<attribute name="Implementation-Version" value="${version}"/>
<attribute name="Group-Id" value="${project_groupid}"/>
<attribute name="Short-Name" value="${project_name}"/>
<attribute name="Long-Name" value="${project_name}"/>
<attribute name="Plugin-Version" value="${project_version}"/>
<attribute name="Jenkins-Version" value="${jenkins_version}"/>
<attribute name="Hudson-Version" value="${jenkins_version}"/>
</manifest>
</jar>
</target>
To launch the build, cd towards the build.xml and type ant.
I know you stated "at all costs", but a compromise might be less effort, and still give super fast builds. A big reason for me to try to avoid maven is that the compile time is sloooowwwwww. That said, maven is quite good at creating the hpl file, and handling dependencies. The following targets are quite useful for helping to set up a super-fast non-maven build:
use 'mvn hpi:hpl' to generate the hpl file
use 'mvn dependency:copy-dependencies' to download all your dependencies, and put them into target/dependency, where it's easy to reference them from your ant script (you can add a symbolic link if necessary, from lib to target/dependency)

TestNG test-output folder getting generated on Desktop when expected to be in project folder

I have a setup of Selenium WebDriver + TestNG + Ant framework in my automation project. Running webdriver + TestNG tests from Ant using build.xml was working absolutely fine a few months ago. TestNG was generating the test-output folder in the project directory as expected. Now when I run my testng tests from ANT it's generating the default report folder test-output on my Desktop (home/user/Desktop). I don't know why it is happening.
This is my build.xml file:
<project name="InitialConfigProject" default="start" basedir=".">
<!-- ========== Initialize Properties =================================== -->
<property environment="env"/>
<property file="./app.properties"/>
<property name="ws.home" value="${basedir}"/>
<property name="test.dest" value="${ws.home}/build"/>
<property name="test.src" value="${ws.home}/src"/>
<property name="browser" value="/usr/bin/google-chrome"/>
<property name="mail_body_file" value="${basedir}/email_body.txt"/>
<property name="buildID" value="IND3.2.0"/>
<property name="sendmailscript_path" value="${basedir}/sendmail.sh"/>
<property name="mail_subject" value="Automated_test_execution_of_${buildID}"/>
<!-- ====== Set the classpath ==== -->
<target name="setClassPath" unless="test.classpath">
<path id="classpath_jars">
<fileset dir="${ws.home}/lib" includes="*.jar"/>
</path>
<pathconvert pathsep=":" property="test.classpath" refid="classpath_jars"/>
</target>
<!-- ============ Initializing other stuff =========== -->
<target name="init" depends="setClassPath">
<tstamp>
<format property="timestamp" pattern="dd/MM/yyyy hh:mm aa" />
</tstamp>
<!--
<condition property="ANT"
value="${env.ANT_HOME}/bin/ant.bat"
else="${env.ANT_HOME}/bin/ant">
<os family="windows" />
</condition> -->
<property name="build.log.dir" location="${basedir}/buildlogs" />
<mkdir dir="${build.log.dir}"/>
<property name="build.log.filename" value="build_${timestamp}.log"/>
<record name="${build.log.dir}/${build.log.filename}" loglevel="verbose" append="false"/>
<echo message="build logged to ${build.log.filename}"/>
<echo message="Loading TestNG.." />
<taskdef name="testng" classpath="${test.classpath}" classname="org.testng.TestNGAntTask" />
</target>
<!-- cleaning the destination folders -->
<target name="clean">
<delete dir="${test.dest}"/>
</target>
<!-- compiling files -->
<target name="compile" depends="init, clean" >
<delete includeemptydirs="true" quiet="true">
<fileset dir="${test.dest}" includes="**/*"/>
</delete>
<echo message="making directory..."/>
<mkdir dir="${test.dest}"/>
<copy file="${ws.home}/app.properties" todir="${ws.home}/build" />
<copy file="${ws.home}/resources/testdata/testDataSet1.properties" todir="${ws.home}/build" />
<echo message="compiling source files..."/>
<javac
debug="true"
destdir="${test.dest}"
srcdir="${test.src}"
target="1.6"
classpath="${test.classpath}"
includeantruntime="true"
>
</javac>
</target>
<!-- run -->
<target name="run" depends="compile">
<testng outputdir="${ws.home}/test-output" classpath="${test.classpath}:${test.dest}" suitename="Praxify Sanity Suite">
<xmlfileset dir="${ws.home}" includes="testng.xml"/>
</testng>
</target>
<!-- ========== Generating reports using XSLT utility ============== -->
<target name="testng-xslt-report">
<delete dir="${basedir}/testng-xslt">
</delete>
<mkdir dir="${basedir}/testng-xslt">
</mkdir>
<xslt in="${basedir}/test-output/testng-results.xml" style="${basedir}/testng-results.xsl" out="${basedir}/testng-xslt/index.html"
processor="SaxonLiaison">
<param expression="${basedir}/testng-xslt/" name="testNgXslt.outputDir" />
<param expression="true" name="testNgXslt.sortTestCaseLinks" />
<param expression="FAIL,SKIP,PASS,CONF,BY_CLASS" name="testNgXslt.testDetailsFilter" />
<param expression="true" name="testNgXslt.showRuntimeTotals" />
<classpath refid="classpath_jars"></classpath>
</xslt>
</target>
<!-- Starting point of the execution, should be dependent on target "run".
Target sequence will be:
start (not_execute) ==> run (not_execute) ==> compile (not_execute) ==> init (execute) ==> clean (execute)
start (execute) <== testng-xslt-report (execute) <== run (execute) <== compile (execute) <==
Suitable for ANT 1.7. Currently using this ====================== -->
<target name="start" depends="run, testng-xslt-report">
<tstamp prefix="getTime">
<format property="TODAY" pattern="MM-dd-yyyyhhmmaa"/>
</tstamp>
<echo message="sending report as mail...."/>
<property name="execution_time" value="${buildID}_${getTime.TODAY}"/>
<property name="dest_file" value="/home/xtremum/Reports/${execution_time}.zip"/>
<zip destfile="/home/xtremum/Reports/${execution_time}.zip" basedir="${basedir}/testng-xslt"/>
<property name="report_attachment_file" value="${dest_file}"/>
<exec executable="${sendmailscript_path}" newenvironment="false">
<arg value="${mail_subject}"/>
<arg value="${mail_recipient}"/>
<arg value="${report_attachment_file}"/>
<arg value="${mail_body_file}"/>
</exec>
</target>
Just for the record:
1. I am using Eclipse Juno.
2. I have installed TestNG plugin on Eclipse so that I can run tests directly from eclipse by right clicking on testng.xml and going for Run.
3. I have installed ANT 1.7 on my Ubuntu machine and have set my ANT_HOME pointing to /usr/share/ant. And I looked up in Windows -> Preferences -> Ant -> Runtime -> Ant Home Entries (Default) and they seem to have references to ant 1.8.3 libraries (JARS) which are inside the Eclipse package (eclipse/plugins/). Is there anything wrong here?
4. I am running the tests via ant from eclipse and not from command line.
I am not getting any build errors. Tests are getting executed but the test-output folder is getting created on Desktop. Any help?
If you are running through the testng plugin option, the output folder would be the one you specify in Project->Properties->TestNG->OutputDirectory

Does the junit.jar has to be in the ant lib directory to run junit task

I was building an Ant build file that worked properly in my eclipse project but not on our Jenkins autobuild set-up. I installed ant on my computer and ran the build from the console. It worked, but I realized it didn't use the junit-4.10.jar in my project lib like I wished but the junit.jar in the ant lib. After renaming the junit.jar files in my ant lib, the ant build didn't work.
So basically the problem in our Jenkins autobuild setup is that there are no junit.jar in its own ant lib directory. Can I specify the junit task to use the jar in my project lib instead of the one in the ant lib?
EDIT : I have modified my build.xml file and now it looks like this, still doesnt work. My junit-4.10.jar is in the /war/WEB-INF/lib/test directory :
<project name="vlp" default="junit" basedir=".">
<tstamp />
<!-- ################# PROPERTIES ################ -->
<!-- directory properties -->
<!-- source -->
<property name="vlp.src" location="src" />
<property name="vlp.test" location="test" />
<!-- build -->
<property name="src.build" location="bin/src" />
<property name="test.build" location="bin/test" />
<!-- libraries -->
<property name="vlp.lib.dir" location="war/WEB-INF/lib" />
<property name="vlp.testlib.dir" location="war/WEB-INF/lib/test" />
<!-- compile classpath -->
<path id="compile.path">
<fileset dir="${vlp.lib.dir}" includes="*.jar" />
</path>
<!-- test classpath -->
<path id="test.path">
<fileset dir="${vlp.testlib.dir}" includes="*.jar" />
<path refid="compile.path" />
</path>
<!-- ############### CLEANING ################## -->
<!-- Cleaning old compile files -->
<target name="clean" description="Clean all the old build files.">
<delete dir="${src.build}" />
<delete dir="${dist}" />
</target>
<!-- ############## COMPILATION ############### -->
<!-- Compile source -->
<target name="src.compile" depends="clean" description="Compile the source code when everything has been cleaned.">
<mkdir dir="${src.build}" />
<javac encoding="utf-8" destdir="${src.build}" nowarn="true">
<src path="${vlp.src}" />
<classpath refid="compile.path" />
</javac>
</target>
<!-- Compile test -->
<target name="test.compile" depends="clean" description="Compile the source code when everything has been cleaned.">
<mkdir dir="${test.build}" />
<javac encoding="utf-8" destdir="${test.build}" nowarn="true">
<src path="${vlp.test}" />
<classpath>
<pathelement location="${src.build}" />
<path refid="test.path" />
</classpath>
</javac>
</target>
<!-- ########### RUNS JUNIT TEST ############ -->
<target name="junit" depends="src.compile,test.compile" description="Runs all the unit test in the application. Does not halt build if test are failed.">
<junit printsummary="on" haltonfailure="false" showoutput="true">
<formatter type="brief" usefile="false" />
<classpath>
<pathelement location="${test.build}" />
<path refid="test.path" />
</classpath>
<batchtest>
<fileset dir="${vlp.test}">
<include name="**/Test*.java" />
<exclude name="**/AllTests.java" />
</fileset>
</batchtest>
</junit>
</target>
</project>
EDIT : Simlar question can be found here with a different answer that works well. Note that it is much easier to install ant-junit on the machine than to try to add it to your libs and everything.
See the answer to this question:
H2 database org.h2.Driver ClassNotFoundException
I normally specify the junit jar to be on a test classpath and then use it when calling the junit ANT task
Update
The following build file is an example of a starting template I used for my builds.
Sets up an infrastructure that uses ivy to manage classpaths. Dependencies are downloaded from the Maven Central repository (by default). Makes build much more portable and repeatable.
build.xml
<project name="ivy demo" default="build" xmlns:ivy="antlib:org.apache.ivy.ant">
<!--
==========
Properties
==========
-->
<property name="build.dir" location="build"/>
<property name="class.dir" location="${build.dir}/classes"/>
<property name="report.dir" location="${build.dir}/reports"/>
<!--
=======
Targets
=======
-->
<target name="install-ivy" description="Used to install the ivy task jar">
<mkdir dir="${user.home}/.ant/lib"/>
<get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.2.0/ivy-2.2.0.jar"/>
</target>
<target name="init" description="Download dependencies, setup project classpaths and create build directories">
<ivy:resolve/>
<ivy:cachepath pathid="compile.path" conf="compile"/>
<ivy:cachepath pathid="runtime.path" conf="runtime"/>
<ivy:cachepath pathid="test.path" conf="test"/>
<ivy:report todir="${report.dir}" graph="false"/>
<mkdir dir="${class.dir}"/>
</target>
<target name="build" depends="init" description="Build the project">
<echo message="Build logic goes here"/>
</target>
<target name="clean" description="Remove build directories">
<delete dir="${build.dir}"/>
</target>
<target name="clean-all" depends="clean" description="Purge ivy cache">
<ivy:cleancache />
</target>
</project>
ivy.xml
This file is used to specify the project's dependencies. Ivy configurations are used to manage the classpath groupings.
<ivy-module version="2.0">
<info organisation="org.demo" module="demo"/>
<configurations>
<conf name="compile"/>
<conf name="runtime" extends="compile"/>
<conf name="test" extends="runtime"/>
</configurations>
<!--
Dependencies can be found using Maven Central's search site:
http://search.maven.org/
-->
<dependencies>
<!-- Compile dependencies -->
<dependency org="org.slf4j" name="slf4j-api" rev="1.6.4" conf="compile->default"/>
<!-- Runtime dependencies -->
<dependency org="log4j" name="log4j" rev="1.2.16" conf="runtime->default"/>
<!-- Test dependencies -->
<dependency org="junit" name="junit" rev="4.10" conf="test->default"/>
</dependencies>
</ivy-module>

Javadoc errors when building Ant project

I am trying to write a build.xml file for my project. When I run build.xml as an Ant project, I get the following error:
D:\workspace\LogAlerter\src\com\j32bit\alerter\launcher\LogAlerter.java:9:
error: package org.apache.log4j does not exist
[javadoc] import org.apache.log4j.Logger;
I have imported log4j in LogAlerter.Java. Here is my build.xml file:
<?xml version="1.0"?>
<project name="LogAlerter" default="main" basedir=".">
<!-- Sets variables which can later be used. -->
<!-- The value of a property is accessed via ${} -->
<property name="src.dir" location="src" />
<property name="build.dir" location="build" />
<property name="dist.dir" location="dist" />
<property name="docs.dir" location="docs" />
<property name="libs.dir" location="lib" />
<!--
Create a classpath container which can be later used in the ant task
-->
<path id="build.classpath">
<fileset dir="${libs.dir}">
<include name="**/*.jar" />
</fileset>
</path>
<!-- Deletes the existing build, docs and dist directory-->
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${docs.dir}" />
<delete dir="${dist.dir}" />
</target>
<!-- Creates the build, docs and dist directory-->
<target name="makedir">
<mkdir dir="${build.dir}" />
<mkdir dir="${docs.dir}" />
<mkdir dir="${dist.dir}" />
</target>
<!-- Compiles the java code (including the usage of library for JUnit -->
<target name="compile" depends="clean, makedir" >
<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="build.classpath" includeantruntime="false">
</javac>
</target>
<!-- Creates Javadoc -->
<target name="docs" depends="compile">
<javadoc packagenames="src" sourcepath="${src.dir}" destdir="${docs.dir}">
<!-- Define which files / directory should get included, we include all -->
<packageset dir="${src.dir}" defaultexcludes="yes">
<include name="**" />
</packageset>
</javadoc>
</target>
<!--Creates the deployable jar file -->
<target name="jar" depends="compile">
<jar destfile="${dist.dir}\LogAlerter.jar" basedir="${build.dir}">
<manifest>
<attribute name="Main-Class" value="LogAlerter.Main" />
</manifest>
</jar>
</target>
<target name="main" depends="compile, jar, docs">
<description>Main target</description>
</target>
</project>
Try adding a classpath ref to your javadoc task:
<javadoc packagenames="src"
sourcepath="${src.dir}"
destdir="${docs.dir}"
classpathref="build.classpath">
What the warning is telling you is that you've not provided the full classpath to the javadoc task. Try adding a similar classpath ref to that in your compile task and see where that leads.
Importing is fine but make sure it is available at run time for the JavaDoc tool. log4j.jar should be present in your build.classpath.
Make use of the classpathref inside the docs target like so:
<javadoc packagenames="src" sourcepath="${src.dir}" destdir="${docs.dir}" classpathref="build.classpath">

Resources