Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javadoc errors when building Ant project

Tags:

javadoc

log4j

ant

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>
like image 444
Olcay Ertaş Avatar asked Dec 21 '22 09:12

Olcay Ertaş


1 Answers

Try adding a classpath ref to your javadoc task:

<javadoc packagenames="src" 
         sourcepath="${src.dir}" 
         destdir="${docs.dir}"
         classpathref="build.classpath">
like image 91
beny23 Avatar answered Dec 28 '22 06:12

beny23