Java – How to make an Ant Javadoc class exclude two files


I am documenting some Java webservices and the supporting datatypes. There are two services that I do not want documented. What is the correct way to exclude a small number of files from the Ant javadoc task?

I have tried several iterations using files or filesets nested under sourcepath or sourcefiles with various combinations of include and exclude.

The base target I have defined correctly documents all of my webservices:

    <target name="javadoc.webservices" description="Generate the documentation for companyproject webservices">
    <delete dir="docs/webservices" failonerror="true"/>
    <mkdir dir="docs/webservices"/>
    <javadoc packagenames=",*"
             windowtitle="company project Webservices">
        <doctitle><![CDATA[<h1>company project Webservices</h1>]]></doctitle>
        <bottom><![CDATA[<i>Copyright &#169; 2011 company Corp. All Rights Reserved.</i>]]></bottom>
            <path location="companyproject-ejb/src/java"/>
            <path location="companyproject-models/src"/>
            <path refid="companyproject-models.module.classpath"/>
            <path refid="companyproject-ejb.module.classpath"/>
            <pathelement location="${companyproject-ejb.output.dir}"/>

Some variations I have tried include:

            <fileset dir="companyproject-ejb/src/java">
                <include name="**/*.java"/>
                <exclude name="**/*IntegrationTestWS*, **/*NhinInterfaceWS*"/>

This errors with javadoc.exe CreateProcess error=87, The parameter is incorrect

            <fileset dir="companyproject-ejb/src/java">
                <include name="**/*.java"/>
                <exclude name="**/*IntegrationTestWS*, **/*NhinInterfaceWS*"/>

Same error as sourcefiles, but has a lot of messages saying skipping <somefile> since it is no directory.

I have tried similar variations using <files> instead of <fileset>.

I think I am missing some basic understanding of how includes/excludes works. Thank you for your help!

AlexR didn't quite get it but came close. I removed <sourcepath> and added

<fileset dir="./Companyproject-ejb/src/java/">
<include name="com/Company/project/webservices/*"/>
<exclude name="**/IntegrationTestWS*"/>
<exclude name="**/NhinInterfaceWS*"/>
<packageset dir="./Companyproject-models/src/">
    <include name="com/Company/project/models/**"/>

Having only a fileset led javadoc to complain that it couldn't find any packages. Packageset behaves like a dirset, so it can't exclude single files, only directories. In this case I was able to define a packageset for one set of doco and a fileset for the restricted set and get around it.

Best Solution

<fileset dir="src" defaultexcludes="yes">
  <include name="com/dummy/test/**"/>
  <exclude name="com/dummy/test/doc-files/**"/>


I think that your mistake is the "sourcefiles" and "sourcepath" tags. Try to remove them. For more information take a look here:

Good luck!