Netbeans Tip

I am posting this in the hope that it will help someone else trying to run a Netbeans Ant build with TeamCity.

Here are a couple of things I have learned to get the classpaths right.  I am using Netbeans 6.5.1.  If you make these changes to your build file and use a later version of Netbeans, good luck.

1.  Add the targets below to the root build.xml (the one that imports nbproject/build-impl.xml).  They let you have project.properties and private.properties files customized for your automated build.  Netbeans uses these files to build the java classpath, and so the need to override them.
2.  Create a file named "auto-project.properties" in the nbproject folder. Modify this file so that the paths to your various jars are correct in terms of your build automation environment.
3.  Create a file named "auto-private.properties" in the nbproject/private folder.  Modify this file the same way as #2.

Note: When I added these files to CVS, Netbeans kept hiding them by putting them in the .cvsignore file.  I had to check them in outside of Netbeans (I edited .cvsignore and used SmartCVS).


    <!-- for debugging the classpath -->

    <target name="-post-init">
        <echo message="javac.classpath = ${javac.classpath}"/>
    </target>



    <!-- team city runs this target -->

    <target name="auto-build">
        <property name="is-auto-build" value="true"/>
        <antcall target="jar"/>  <!-- "jar" is a target inside build-impl.xml; when running a build inside netbeans it calls this -->
    </target>



    <!-- overrides the -pre-init target inside netbeans to use a custom properties file -->

    <target depends="-pre-init" name="-init-private">
        <condition property="private.properties" value="auto-private.properties" else="private.properties">
            <and>
                <isset property="is-auto-build"/>
            </and>
        </condition>


        <property file="nbproject/private/config.properties"/>
        <property file="nbproject/private/configs/${config}.properties"/>
        <property file="nbproject/private/${private.properties}"/>
    </target>



    <!-- overrides the -init-project target inside netbeans to use a custom properties file -->
    <target depends="-pre-init,-init-private,-init-user" name="-init-project">
        <condition property="project.properties" value="auto-project.properties" else="project.properties">
            <and>
                <isset property="is-auto-build"/>
            </and>
        </condition>


        <property file="nbproject/configs/${config}.properties"/>
        <property file="nbproject/${project.properties}"/>
    </target>

Please sign in to leave a comment.