Once you've got your build script working and your classpath in an ant property, you can get the two main IDE's to use them:

Make an ant target to generate your eclipse .classpath file

Note that this uses the ant-contrib module for the for-each task. You must get this jar and add it to ant's classpath

 

    <target name="-init-eclipse-tasks">
        <echo>initing ant-contrib tasks for eclipse generation</echo>
        <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>   
    </target>
 
    <target name="-generate-project" description="Generate the .project file">
        <echo>generating eclipse project file</echo>
        <concat destfile=".project" append='no'><![CDATA[
<projectDescription>
    <name>${project.name}</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>com.ibm.sse.model.structuredbuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>
</projectDescription>
        ]]></concat>
    </target>

    <target name="-generate-classpath">
        <echo>generating eclipse classpath file</echo>
        <concat destfile=".classpath" append='no'><![CDATA[
<classpath>
    <classpathentry kind="src" path="JavaSource"/>
    <classpathentry kind="src" path="UnitTestSource"/>
        ]]></concat>   
        <foreach list="${cp.test.compile}" delimiter=";" param="lib" target="-generate-lib" />
        <concat destfile=".classpath" append='yes'><![CDATA[
    <classpathentry kind="output" path="bin"/>
</classpath>           
        ]]></concat>   
    </target>

    <target name="-generate-lib">
        <var name="lib.relative" value="" unset="true" />
        <propertyregex property="lib.relative"
              input="${lib}"
              regexp="([^\.]*)EndorsementsHandler\\(.*)"
              select="\2"
              casesensitive="false" />

        <concat destfile=".classpath" append='yes'><![CDATA[
    <classpathentry kind="lib" path="${lib.relative}"/>]]></concat>       
    </target>

 

Configure a netbeans project to use your external classpath

Make a free form project then edit your nbproject/project.xml file. Import the properties file(s) and put ant property values into the classpath elements.

...

            <name>MyProject</name>
            <properties>
                <property-file>cp.compile.properties</property-file>
                <property-file>cp.test.compile.properties</property-file>
            </properties>
...

        <java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/2">
            <compilation-unit>
                <package-root>JavaSource</package-root>
                <classpath mode="compile">${cp.compile}</classpath>
                <built-to>bin</built-to>
                <javadoc-built-to>docs/api</javadoc-built-to>
                <source-level>1.4</source-level>
            </compilation-unit>
            <compilation-unit>
                <package-root>UnitTestSource</package-root>
                <unit-tests/>
                <classpath mode="compile">${cp.test.compile}:JavaSource</classpath>
                <built-to>bin</built-to>
                <source-level>1.4</source-level>
            </compilation-unit>
        </java-data>

Note that this method relies on having your classpath in a property file, which is not always the case. If your classpath ends up in a reference you can get it into a property file like this:

        <property name="cp.compile" refid="cp.compile.id" />

        <propertyfile file="cp.compile.properties">
            <entry operation="=" key="cp.compile" value="${cp.compile}"/>
        </propertyfile>