开发者

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">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜