Problems with setting the classpath in ant

I think the problem is with your classpath path declaration. The build directory should be a <pathelement>

<path id="classpath">
    <fileset dir="${lib}">
        <include name="**/*.jar" />
    </fileset>
    <pathelement location="${build}" />
</path>

Also, I would only include 3-rd party jars in your classpath refid. So the whole block looks like.

<path id="3rd-party-classpath">
    <fileset dir="${lib}">
        <include name="**/*.jar" />
    </fileset>
</path>

<target name="build">
    <javac srcdir="${src}" destdir="${build}">
        <classpath refid="3rd-party-classpath" />
    </javac>
</target>

<target name="run">
    <java classname="FirstClass">
      <classpath>
        <pathelement location="${build}" />
        <path refid="3rd-party-classpath" />
      </classpath>
    </java>
</target>

Also, as DroidIn.net has pointed out, you should create a package for you program.

Leave a Comment