Javadoc Errors When Creating an 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 imported log4j to 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> 
+4
source share
3 answers

Try adding a link to the path to your javadoc task:

 <javadoc packagenames="src" sourcepath="${src.dir}" destdir="${docs.dir}" classpathref="build.classpath"> 
+7
source

What warns you of the warning is that you did not provide the full path to the javadoc class. Try adding a similar path path to that in your compiled task and see what this leads to.

+2
source

The import is fine, but make sure it is available at run time for the JavaDoc tool. log4j.jar should be present in your build.classpath .

Use classpathref inside the docs target like this:

 <javadoc packagenames="src" sourcepath="${src.dir}" destdir="${docs.dir}" classpathref="build.classpath"> 
+2
source

All Articles